socket: Use a default listen backlog of -1 on Linux #1387
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On FreeBSD, OpenBSD & macOS we use a default listen(2) backlog of -1 which means use the OS's default value.
On Linux (and others) we used a hard coded value of 511, presumably due to this comment
/* Linux, Solaris, and NetBSD treat negative value as 0. */
On Linux (at least since 2.4), this is wrong, Linux treats -1 (and so on) as use the OS's default (net.core.somaxconn). See this code in net/socket.c::__sys_listen()
On Linux prior to 5.4 somaxconn defaulted to 128, since 5.4 it defaults to 4096.
We've had complaints that a listen backlog of 511 is too small. This would help in those cases.
Unless they are on an old Kernel, in which case it's worse, but then the plan is to also make this configurable. This would effect RHEL 8, which is based on 4.10, however they seem to set somaxconn to 2048, so that's fine.
Another advantage of using -1 is that we will automatically keep up to date with the kernels default value.
Before this change
After