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

Have bernhard attempt to set SO_REUSEADDR. #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kainz
Copy link

@kainz kainz commented Jul 21, 2015

On an app with heavy TCP traffic, this will minimize the use of extra
TCP IP/port pairs.

Bryon Roche added 2 commits July 21, 2015 11:37
On an app with heavy TCP traffic, this will minimize the use of extra
TCP IP/port pairs.
@b20n
Copy link
Owner

b20n commented Aug 5, 2015

I'm not following the need here. Why is your app creating and tearing down clients with any frequency?

@kainz
Copy link
Author

kainz commented Aug 5, 2015

My app is not, any longer. An older revision of it was. That said:

If you have any process opening and closing TCP client sockets quickly to a given server (say, your DB), if you are not using SO_REUSEADDR you will fail to connect to the remote end due to port exhaustion.

The root cause is port exhaustion due to sockets in TCP TIME_WAIT state.

On a linux system with default TCP stack settings you have roughly 16384 available ephemeral ports (per destination address), and your defaut TIME_WAIT timeout is two minutes. That roughly means that you can trigger port exhaustion in this situation with as few as 136 connections/sec.

Varnish, nginx, and haproxy are examples of applications which could easily trigger this situation. Setting SO_REUSEADDR on client connections mitigates this by allowing port number/ip address combinations to be reused before that timeout in certain situations.

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.

2 participants