Add Kestrel port sharing support to some Linux benchmarks #2025
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.
As noted in the code comments, this same socket option works on Windows, but it doesn't round robin new connections between processes like it does on Linux.
https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#using-so_reuseaddr
This makes it a decent option for resiliency on Windows, but not for benchmarking, so I decided not to set SO_REUSEADDR on Windows. This way we don't lose out on address in use errors when you might not realize you were trying to bind multiple processes to the same port. We could make this opt-in on Linux as well if we want to keep getting address in use errors unless you're specifically testing multiple process bound to the same port on Linux.
It's probably also worth noting that the runtime networking PAL translates SO_REUSEADDR to SO_REUSEPORT on Linux since that gives behavior more similar to SO_REUSEADDR on Windows than SO_REUSEADDR on Linux does. We could use
SetRawSocketOption
instead, but this way we don't have to use magic numbers, and this is a use case forSetSocketOption
that's supported and tested by the runtime on Linux.I also didn't change the behavior on macOS or FreeBSD because I didn't test this on those platforms. Socket options are famously handled differently by different OS's and that's especially true for SO_REUSEADDR and SO_REUSEPORT. https://stackoverflow.com/a/14388707/719967 is an excellent writeup on these options and how they behave on various operating systems. I encourage anyone who's interested to give it a read and upvote it if they're interested.