Skip to content
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

fix(dealer): make net.Dialer not to bind to reuse ephimeral ports #181

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

dkropachev
Copy link
Collaborator

@dkropachev dkropachev commented May 30, 2024

net.Dialer makes golang runtime run bind if LocalAddr is not nil, even if address is ":0".
https://github.com/golang/go/blob/master/src/net/sock_posix.go#L109-L117

Calling bind, due to it's nature, marks obtained port as non-reusable, which limits number of possible connections/sessions.

It is inevitable for share-aware connections, since we need to pick the port, but for none-shard-aware connections it must be avoided.

Closes #179

@mykaul mykaul requested a review from sylwiaszunejko May 30, 2024 07:07
@roydahan
Copy link
Collaborator

roydahan commented Jun 2, 2024

@sylwiaszunejko do we need another maintainer reviewing it?
If so, please get someone to review and merge.

Also, please make sure we have tests to detect such an issue (looks like we don't).

@sylwiaszunejko
Copy link
Collaborator

sylwiaszunejko commented Jun 3, 2024

@avelanarius Could you look at it to make sure it LGTM?

@sylwiaszunejko sylwiaszunejko merged commit 4b1e57a into scylladb:master Jun 3, 2024
1 check passed
@sylwiaszunejko
Copy link
Collaborator

@dkropachev I was wondering how to write a test for this, but I am not sure. I was trying to use the issue reproducer, but without fmt.Println("Routine:", routine, "Try:", try) the issue stopped reproducing and with it or with analogues logging statement there was a error like that: testing.go:1465: race detected during execution of test. Do you have any ideas how to minimize reproducer or how to test this change some other way?

@dkropachev
Copy link
Collaborator Author

@dkropachev I was wondering how to write a test for this, but I am not sure. I was trying to use the issue reproducer, but without fmt.Println("Routine:", routine, "Try:", try) the issue stopped reproducing and with it or with analogues logging statement there was a error like that: testing.go:1465: race detected during execution of test. Do you have any ideas how to minimize reproducer or how to test this change some other way?

There is no good way of doing it.
We could have an interface with something like :

DialContext(ctx context.Context, network, addr string) (net.Conn, error)
DialContextWithPort(ctx context.Context, network, addr string, sport uint16) (net.Conn, error)

And then mock it on test, but realy, this test won't acheve anything.
To me better just not test it at all

@sylwiaszunejko
Copy link
Collaborator

@roydahan FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Connection can randomly fail with address already in use
3 participants