gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

Set SO_KEEPALIVE on listener socket

Open cedk opened this issue 1 year ago • 5 comments

Closes #3115

cedk avatar Dec 15 '23 22:12 cedk

What scenario would this be useful in (or even observably different from defaults)? Are you concerned about the 2 hour timeframe, which I fear may not be easy to write a test for on non-Linux systems?

pajod avatar Dec 27 '23 01:12 pajod

While the Linux default is 2 hours before keepalives start, and that is much higher than a typical Gunicorn HTTP keep-alive timeout, it's still a fine idea for cases where someone does set a very high HTTP keep-alive timeout or wants to detect stalled, long-lived requests or something. Maybe they set their system keepalive timeout to be very low.

Nevertheless, it's not enabled at all unless we set this socket option, so I think we probably should make that possible.

tilgovi avatar Dec 27 '23 01:12 tilgovi

The original linked issue talks about closing long running connections. A good example of where this is useful is probably if someone uses gunicorn with an application that handles WebSocket upgrades.

tilgovi avatar Dec 27 '23 01:12 tilgovi

I agree this should be an option. Using it as default will break some behaviors.

I am also unsure why it's needed for a proxy, HTTP connections should be stateless but it's good addion as an option anyway.

benoitc avatar Jan 05 '24 08:01 benoitc

Indeed our host tells us to send keep-alive to avoid the proxy to close the request before it is answered. But now they came back on this statement and just ask us to use asynchronous request.

So I'm no more sure if this option will be useful for us but I can add the option.

cedk avatar Jan 05 '24 23:01 cedk

commented related ticket. closing as WON4T DO IT

benoitc avatar Aug 06 '24 17:08 benoitc