-
Notifications
You must be signed in to change notification settings - Fork 990
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
Skip connecting PeerWithSelf by checking ip address #2253
Conversation
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 wonder why do we need the second check, perhaps in some cases we don’t handle the error during handshake?
@garyyu and did that PR improve your connection count? It seems odd you'd have to add another test that's based on the first. Perhaps also make sure the |
@hashmap @ignopeverell thanks for the review.
More test will be done today. One node tested yesterday but it didn't happen after a restart (no much PeerWithSelf as before).
Also odd to me. I can't imagine what exactly make this happen, so the only way is to do a real test to check.
And this node can't accept TCP connection on port 13414 anymore:
I think those nodes in
All 3 nodes in this seed can't accept any new connections at this moment. Perhaps you check and confirm, with above commands.
I added one more step to shutdown the TcpStream when detected PeerWithSelf. I'm not sure whether this |
More problems found:
I think if we can kill case 1, then this case 2 will not happen. [Updated]: |
After 24 hours tests on 3 servers, there's no more self connection. We can see some logs like this:
It works as expected. Merging now.... and then I switch to issue #2258 which now becomes the main problem causing seed nodes un-connectable after this fix. |
let addrs = hs.addrs.read(); | ||
if addrs.contains(&addr) { | ||
debug!( | ||
"connect: ignore the connecting to PeerWithSelf, addr: {}", |
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.
"ignore connecting to {}" sounds more accurate
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.
👍 thanks, and I will correct this word in next PR.
@@ -29,13 +29,16 @@ use crate::peer::Peer; | |||
use crate::types::{Capabilities, Direction, Error, P2PConfig, PeerInfo, PeerLiveInfo}; | |||
|
|||
const NONCES_CAP: usize = 100; | |||
const ADDRS_CAP: usize = 10; |
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.
It would be nice to comment on why these magic numbers are chosen.
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.
agree~
My server can't be connected any more but the total connected peers is far below the configured
peer_max_count
, less than 30 peers, check by netstat:And check detail on one server, I find 160 TCP connections by itself. I don't know how but it do connect to itself and keep these connections.
This PR give an improvement on current PeerWithSelf detection solution (by nonce which store 100 recent nonces it generated/sent in Hand).
And add one more step for PeerWithSelf:
shutdown
the TcpStream.[Updated]
I find it's more clean to skip self connecting (on requester side), compared to double check nonce and ip address (on listener side).