msquic icon indicating copy to clipboard operation
msquic copied to clipboard

Why is the motivation to always set `SO_REUSEPORT` for servers

Open pepone opened this issue 3 years ago • 9 comments

https://github.com/microsoft/msquic/blob/5b921c9e187d2c59a43ec285be1a06e99349d1b2/src/platform/datapath_epoll.c#L1173-L1195

My understanding is that this code always set SO_REUSEPORT for a server, and you will not get the address already in use when two servers use the same address, what is the motivation for this? did you consider making it configurable?

pepone avatar Oct 21 '22 15:10 pepone

We create per-processor sockets to efficiently scale and align with RSS.

nibanks avatar Oct 21 '22 15:10 nibanks

Would be nice if applications can configure this behavior

pepone avatar Oct 24 '22 13:10 pepone

Would be nice if applications can configure this behavior

May I ask why?

nibanks avatar Oct 24 '22 13:10 nibanks

Because if two different server applications happen to configure the same address and port, it would be nice to get an error, this is the most expected behavior for a server.

pepone avatar Oct 24 '22 13:10 pepone

So, you'd prefer to get an error in this case rather than have the performance/scale of using multiple processors on the server side?

nibanks avatar Oct 24 '22 13:10 nibanks

I talking about two unrelated application servers configured in the same address port, for example, two HTTP servers handling different applications, in this case, you deserve to get an error yes.

pepone avatar Oct 24 '22 13:10 pepone

On Windows, the second process would get an error code indicating that the requested listening address is already in use (EADDRINUSE), it would be nice to have consistent behavior across platforms if it can be achieved without significant performance loss.

rzikm avatar Nov 21 '22 13:11 rzikm

Any thoughts here @tmds? Basically we need multiple sockets on the same port to load-balance inbound UDP traffic via RPS

wfurt avatar May 09 '23 15:05 wfurt

You're setting SO_REUSEPORT (on Linux) to distribute UDP packets across multiple receiving sockets.

There is no way to prevent another process (that runs as the same user) from creating additional receiving socket.

tmds avatar May 10 '23 08:05 tmds