New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't check if the listening socket is valid #23601
Don't check if the listening socket is valid #23601
Conversation
Listening sockets in `CConnman::vhListenSocket` are always valid (underlying file descriptor is not `INVALID_SOCKET`).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-review ACK 6c9ee92 🔌
Verified that it's currently not possible that CConnman::vhListenSocket
ever contains invalid sockets. The only place where an element gets added to the vector is in the method CConnman::BindListenPort
:
Line 2394 in 111c3e0
vhListenSocket.push_back(ListenSocket(sock->Release(), permissions)); |
which would already return earlier (directly after CreateSock(...)
) if the socket contained in the sock
wrapper was not valid. Also built and ran unit tests locally with success.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK.
If INVALID_SOCKET
can get into recv_set
, we have UB earlier anyway. Therefore, .count
should always be 0 even if somehow listen_socket.socket
were INVALID_SOCKET
.
If this is safe, is there a reason why it can't be removed here as well? src/net.cpp=void CConnman::StopNodes()
src/net.cpp-{
...
src/net.cpp-
src/net.cpp- // Close listening sockets.
src/net.cpp: for (ListenSocket& hListenSocket : vhListenSocket) {
src/net.cpp- if (hListenSocket.socket != INVALID_SOCKET) { |
@MarcoFalke, that's right - can be removed from here too and should have been part of this PR, I missed it. I missed it because in #21878 that "close listening sockets" code becomes unnecessary and is removed: - // Close listening sockets.
- for (ListenSocket& hListenSocket : vhListenSocket) {
- if (hListenSocket.socket != INVALID_SOCKET) {
- if (!CloseSocket(hListenSocket.socket)) {
- LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAG
- }
- }
- } This removal is also in #21879 which is chopped off from the big #21878 to ease review. I will leave it as is to avoid further conflicts, hoping that #21879 will eventually make it in. |
6c9ee92 net: don't check if the listening socket is valid (Vasil Dimov) Pull request description: _This is a piece of bitcoin#21878, chopped off to ease review._ Listening sockets in `CConnman::vhListenSocket` are always valid (underlying file descriptor is not `INVALID_SOCKET`). ACKs for top commit: theStack: Code-review ACK 6c9ee92 🔌 Tree-SHA512: b2e29711c6a0c7c85467ca61cfd7fb734eb06bd83a41f88735901caf90aec095ca80707ce5bb897d39c80fdec16819dbf5a84979c9b1ab3dc3fb8b08cebe7c61
…alid 86ec664 net: don't check if the listening socket is valid (Vasil Dimov) Pull request description: _This is a piece of #21878, chopped off to ease review._ Listening sockets in `CConnman::vhListenSocket` are always valid (underlying file descriptor is not `INVALID_SOCKET`). ACKs for top commit: theStack: Code-review ACK 86ec664 🔌 Tree-SHA512: b2e29711c6a0c7c85467ca61cfd7fb734eb06bd83a41f88735901caf90aec095ca80707ce5bb897d39c80fdec16819dbf5a84979c9b1ab3dc3fb8b08cebe7c61
This is a piece of #21878, chopped off to ease review.
Listening sockets in
CConnman::vhListenSocket
are always valid(underlying file descriptor is not
INVALID_SOCKET
).