-
Notifications
You must be signed in to change notification settings - Fork 405
[Transfer Engine] Prevent binding the same port for multiple instances #627
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
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 1cb4370.
|
Hi @alogfans, I met the problem when the two process listen on the same port (e.g. 16474 is used by two process) and then the following error message appears. So I think it would be best not to allow multiple processes to bind to the same port, but does your PR increase the likelihood of this happening? If SO_REUSEPORT is set, multiple sockets are bound to an identical socket address. Therefore, multiple processes can listen to the same port. Is there a problem somewhere? |
|
It seems reusing port cannot solve the problem. @alogfans |
|
@staryxchen Thanks for your feedback. We use two methods to avoid this problem:
|
@alogfans I think the easiest way to fix this is to reduce the likelihood of port conflicts by expanding the range of randomly selected ports. Here's an example of what I wrote, just for reference. |
|
Enlarge port space is a good idea. Also we make REUSEADDR disabled by default. Thus the problem should be fixed. |
@alogfans Nice work, but I have two more questions:
|
|
Understood. LGTM |
| if (getenv("MC_ENABLE_REUSEADDR")) { | ||
| int on = 1; | ||
| if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) { | ||
| close(sockfd); | ||
| sockfd = -1; | ||
| continue; | ||
| } | ||
| } |
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.
we'd better remove these lines? multiple TE reuse the same port is not expected, since only one TE could accept the connection from client.
Setting SO_REUSEPORT to 1, which avoids bind the same port twice.