-
Notifications
You must be signed in to change notification settings - Fork 37.8k
net: implement poll #14336
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
net: implement poll #14336
Conversation
f5aa8cf
to
6bcefaa
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
6bcefaa
to
a97afdf
Compare
80e59ca
to
7fd976b
Compare
It seems that lots of the functional tests have races cause this pull request keeps triggering random seeming failures. |
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.
Concept ACK
int nErr = WSAGetLastError(); | ||
LogPrintf("socket select error %s\n", NetworkErrorString(nErr)); | ||
for (unsigned int i = 0; i <= hSocketMax; i++) | ||
FD_SET(i, &fdsetRecv); |
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.
I see this is the same as the code currently, but it seems like this should be fdsetError
instead of fdsetRecv
, even though they are handled exactly the same.
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.
I don't think it should be there at all really. select() failures dont mean the sockets themselves have failed, but i guess it could mean we made a mistake and called select() with a closed 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.
Yeah, then iterating through each one and calling recv
would identify which peer to disconnect. Though, if it's fdsetError
and not fdsetRecv
, it probably shouldn't disconnect when nBytes == 0
.
5cf67c9
to
e4db5b3
Compare
Concept ACK, will review in detail when my brain works again. |
cd28216
to
499bdef
Compare
Concept ACK. Will also review shortly. |
7acadee
to
84fae8d
Compare
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.
Some minor comments and a question about conservatively falling back to select
for MacOS systems. Code looks good!
This separates the socket event collection logic from the logic deciding which events we're interested in at all.
This separates the select() logic from the socket handling logic, setting up for a switch to poll().
cc6edb4
to
20c9601
Compare
With 87 connections the effect of generating the pollfd list shows up on a profile but isn't significant. The poll() implementation is on the order of 1000 ns slower per call than the select() implementation. I don't think that's significant. |
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 20c9601
Code looks good, feel free to ignore the small comments. I'm running tests at the moment and will report back with results within the next day - testnet happy-path behavior looks good so far.
} | ||
} | ||
#else | ||
void CConnman::SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set) |
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.
(non-blocking)
diff --git a/src/net.cpp b/src/net.cpp
index 7b8b6e5ea2..03d165d701 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1355,6 +1355,7 @@ void CConnman::SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_s
}
}
#else
+// Use select() on platforms where poll() is unavailable.
void CConnman::SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set)
{
std::set<SOCKET> recv_select_set, send_select_set, error_select_set;
struct timeval tval = MillisToTimeval(std::min(endTime - curTime, maxWait)); | ||
fd_set fdset; | ||
FD_ZERO(&fdset); | ||
FD_SET(hSocket, &fdset); | ||
int nRet = select(hSocket + 1, &fdset, nullptr, nullptr, &tval); | ||
#endif | ||
if (nRet == SOCKET_ERROR) { |
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.
(non-blocking) This might be academic, but since this clause is handling both select()
and poll()
might be safer to say if (nRet < 0)
? Though right now there's no difference in the return value for both APIs (and I doubt that'll ever change...).
This eliminates the restriction on maximum socket descriptor number.
20c9601
to
4927bf2
Compare
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.
Tested ACK 4927bf2
Tested on Linux 4.15.0-39-generic and macOS 10.12.1. Tested IBD on testnet as well as tweaking -maxconnections
and observing connections with lsof -a -itcp -p $(pidof bitcoind)
.
Only code change since my last utACK is a small cleanup in netbase.cpp.
Thanks for the work here @pstratem.
utACK 4927bf2 |
4927bf2 Increase maxconnections limit when using poll. (Patrick Strateman) 11cc491 Implement poll() on systems which support it properly. (Patrick Strateman) 28211a4 Move SocketEvents logic to private method. (Patrick Strateman) 7e403c0 Move GenerateSelectSet logic to private method. (Patrick Strateman) 1e6afd0 Introduce and use constant SELECT_TIMEOUT_MILLISECONDS. (Patrick Strateman) Pull request description: Implement poll() on systems which support it properly. This eliminates the restriction on maximum socket descriptor number. Tree-SHA512: b945cd9294afdafcce96d547f67679d5cdd684cf257904a239cd1248de3b5e093b8d6d28d8d1b7cc923dc0b2b5723faef9bc9bf118a9ce1bdcf357c2323f5573
Crashes on android 7 8 and 9 armv7a. May need to implement a work around |
Summary: Partial backport of Core [[bitcoin/bitcoin#14336 | PR14336]] bitcoin/bitcoin@1e6afd0 Test Plan: ninja ninja check Reviewers: O1 Bitcoin ABC, #bitcoin_abc, majcosta, jasonbcox Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, majcosta, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6459
Summary: This separates the socket event collection logic from the logic deciding which events we're interested in at all. Partial backport of Core [[bitcoin/bitcoin#14336 | PR14336]] bitcoin/bitcoin@7e403c0 Depends on D6459 Test Plan: ninja ninja check-all src/bitcoind -debug=net Verify normal node connection behavior Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien, jasonbcox Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien, jasonbcox Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D6460
Summary: This separates the select() logic from the socket handling logic, setting up for a switch to poll(). Partial backport of Core [[bitcoin/bitcoin#14336 | PR14336]] bitcoin/bitcoin@28211a4 Depends on D6460 Test Plan: ninja ninja check-all src/bitcoind -debug=net Verify normal node behavior. Reviewers: O1 Bitcoin ABC, #bitcoin_abc, majcosta, jasonbcox Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, majcosta, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6461
Summary: This eliminates the restriction on maximum socket descriptor number. Partial backport of Core [[bitcoin/bitcoin#14336 | PR14336]] bitcoin/bitcoin@11cc491 Depends on D6461 Test Plan: ninja ninja check-all src/bitoind Verify normal node behavior. Reviewers: O1 Bitcoin ABC, #bitcoin_abc, majcosta Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6470
Summary: Partial backport of Core [[bitcoin/bitcoin#14336 | PR14336]] bitcoin/bitcoin@4927bf2 Depends on D6470 Test Plan: ninja ninja check-all src/bitcoind --debug=net Verify normal node behavior. Reviewers: O1 Bitcoin ABC, #bitcoin_abc, majcosta Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D6471
They are outdated since bitcoin#14336.
ee7891a doc: Remove outdated comments (Hennadii Stepanov) Pull request description: The first removed comment was introduced in #5288, the second one in #13503. Both are outdated since #14336. ACKs for top commit: duncandean: crACK ee7891a Tree-SHA512: a2d6071919e81c916bfc2178109bbc464417321bcc567ed0644448c5faea8e58cb08a7657afa1b6ffe1fb63e114a2a47b31c893e471839ba9d49a3986e68b2a7
ee7891a doc: Remove outdated comments (Hennadii Stepanov) Pull request description: The first removed comment was introduced in bitcoin#5288, the second one in bitcoin#13503. Both are outdated since bitcoin#14336. ACKs for top commit: duncandean: crACK ee7891a Tree-SHA512: a2d6071919e81c916bfc2178109bbc464417321bcc567ed0644448c5faea8e58cb08a7657afa1b6ffe1fb63e114a2a47b31c893e471839ba9d49a3986e68b2a7
…t correctly 8ff3743 Revert "doc: Remove outdated comments" (Hennadii Stepanov) Pull request description: Unfortunately, in #23094 the assumption that #14336 makes comments outdated is wrong. As pointed in #23094 (comment), the #14336 just moved the relevant code a few lines down. This PR reverts commit ee7891a, and moves the comments into the right place. I apologize about that. ACKs for top commit: MarcoFalke: cr ACK 8ff3743 laanwj: ACK 8ff3743 Tree-SHA512: 84aca627bb5b49c06fc172778f9b9407482c5a873ccbc3dc40167e6a8ad0bc60475d6a469c843b7b42712e35cf3fc2d3518923e791d5e0c59628e042acc72747
… comment correctly 8ff3743 Revert "doc: Remove outdated comments" (Hennadii Stepanov) Pull request description: Unfortunately, in bitcoin#23094 the assumption that bitcoin#14336 makes comments outdated is wrong. As pointed in bitcoin#23094 (comment), the bitcoin#14336 just moved the relevant code a few lines down. This PR reverts commit ee7891a, and moves the comments into the right place. I apologize about that. ACKs for top commit: MarcoFalke: cr ACK 8ff3743 laanwj: ACK 8ff3743 Tree-SHA512: 84aca627bb5b49c06fc172778f9b9407482c5a873ccbc3dc40167e6a8ad0bc60475d6a469c843b7b42712e35cf3fc2d3518923e791d5e0c59628e042acc72747
They are outdated since bitcoin#14336.
Implement poll() on systems which support it properly.
This eliminates the restriction on maximum socket descriptor number.