pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Socket remains ESTABLISHED after `keep_alive_timeout`

jonathanslenders opened this issue · comments

The keep_alive_timeout config does cause the TLS stream to be terminated, but it won't close the underlying socket, which remains in the ESTABLISHED state.

This was discovered while troubleshooting an httpx issue. See: encode/httpx#2983

I can see that Hypercorn does call asyncio.StreamWriter.close() after the idle timeout. However, the transport is of type asyncio.sslproto._SSLProtocolTransport, which means there's no guarantee that the actual socket is closed. Looking at netstat, the TCP socket remains ESTABLISHED even after Hypercorn tries to close the writer.

Of course, if the HTTP client responds to the TLS termination by closing the socket from the client's side, it will get closed, but otherwise, the socket will remain open.

Maybe we want to fix this.