-
Notifications
You must be signed in to change notification settings - Fork 113
Avoid TcpListener port collisions
#718
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
Avoid TcpListener port collisions
#718
Conversation
|
👋 Thanks for assigning @joostjager as a reviewer! |
da47569 to
bfda813
Compare
|
Hmm, even with the current changes I didn't get much insight into the |
bfda813 to
1b7d919
Compare
|
Now reopened instead of #719. |
joostjager
left a comment
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.
Nothing blocking
|
|
||
| for _ in 0..num_addresses { | ||
| let rand_port = random_port(); | ||
| while listening_addresses.len() < num_addresses { |
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 think the former for loop can remain?
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.
Well, I'm not sure that there is a guarantee that we don't get the same port back if we drop socket each iteration. I guess we could push them to a Vec to keep them alive while we're still iterating, but this seemed easier.
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.
Hmm although obvious, I didn't realize that we don't actually use the socket. In that case, it definitely seems better to keep the sockets alive?
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.
Hmm although obvious, I didn't realize that we don't actually use the socket. In that case, it definitely seems better to keep the sockets alive?
No, why? We def. don't want to keep it alive to allow the Node setup a new one?
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 mean during the iteration, for the reason you brought up?
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.
Right, but the OS likely gives back random available ports, and we dedup via the HashSet, so we're good?
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.
Idk if that is always the case for all OSes? Seems there is endless loop potential here. It's just test, fine to leave as is, but it doesn't feel 100% solid.
Previously, we could in tests potentially run into listening port collisions resulting into `InvalidSocketAddress` errors. These errors could surface if we rolled port numbers that either collided with other concurrent tests *or* with other unrelated services running on localhost. Here, we simply let the OS assign us a free port number when setting up the testing nodes, which avoids such collisions altoghether (mod the potential TOCTOU race here, which we ignore for now).
1b7d919 to
c0b4933
Compare
|
|
||
| for _ in 0..num_addresses { | ||
| let rand_port = random_port(); | ||
| while listening_addresses.len() < num_addresses { |
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.
Idk if that is always the case for all OSes? Seems there is endless loop potential here. It's just test, fine to leave as is, but it doesn't feel 100% solid.
Second, more thorough attempt:
Previously, we could in tests potentially run into listening port collisions resulting into
InvalidSocketAddresserrors. These errors could surface if we rolled port numbers that either collided with other concurrent tests or with other unrelated services running on localhost.Here, we simply let the OS assign us a free port number when setting up the testing nodes, which avoids such collisions altoghether (mod the potential TOCTOU race here, which we ignore for now).