Skip to content

Tell the client the connection is closing after each response - #212

Open
arpitjain099 wants to merge 1 commit into
coder:mainfrom
arpitjain099:fix/signal-connection-close
Open

Tell the client the connection is closing after each response#212
arpitjain099 wants to merge 1 commit into
coder:mainfrom
arpitjain099:fix/signal-connection-close

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #211.

handleHTTPConnection and handleTLSConnection each read one request and close the connection in a defer, but neither response says so. The upstream Connection: keep-alive is not passed through either, so a client that pools sockets, Node's https.Agent({keepAlive: true}) in the report, keeps the socket and the next write lands on a connection the proxy has already gone away from. That is the alternating socket hang up in the issue, and it is why code-server --install-extension fails outright and npm install crawls.

RFC 9112 section 9.6 puts that on the sender: if you are going to close, say so. The forwarded response now drops any upstream Connection header and sets resp.Close, so Response.Write emits Connection: close, and the blocked 403 does the same.

This is the first of the two options in the issue. Actually keeping connections alive, the second option, is the better outcome for throughput, but it means holding the connection open and looping over requests in both handlers, which is a larger change and a design call for you rather than something to slip into a bug fix.

The test starts a local backend, goes through the proxy for one allowed and one blocked request, and asserts resp.Close on both. It fails on main with "response must tell the client the connection is closing". go test -race ./proxy/ passes.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep-alive connections are closed without Connection: close, breaking socket reuse (code-server extension install fails; npm ~90x slower)

1 participant