jupyterhub / configurable-http-proxy

node-http-proxy plus a REST API
BSD 3-Clause "New" or "Revised" License
242 stars 130 forks source link

Enable keep-alive, `--keep-alive-timeout` flag added (default: 5000ms) #492

Closed minrk closed 1 year ago

minrk commented 1 year ago

extends #481 to enable keepAlive not just on the server, but on proxied requests as well via an http agent, and exposing timeout on the command-line.

alternative to #491 using the standard library

closes #481 closes #491

consideRatio commented 1 year ago

I don't understand the details well enough to review this.

Are there two connections to consider (or more, or something else)? The connection initiated to the proxy (A->proxy), and the one the proxy initiated to some destination (proxy->B)?

Is "agent" associated with the connection towards the proxy, and "server" associated with the connection from the proxy onwards to some destination?

minrk commented 1 year ago

Are there two connections to consider (or more, or something else)? The connection initiated to the proxy (A->proxy), and the one the proxy initiated to some destination (proxy->B)?

Yes, both of these. The agent is the pool used to allow keeping connections alive for the proxy->backend requests. The keepAlive argument is for requests to the proxy. We need both of these because the keep-alive propagates all the way through the proxy, and if either server (the proxy or the backend) sets Connection: close the connections will be closed all the way up. This is because the proxy server relays the Connection header to the lowest value.

If any of the 4 entities involved (the client, the proxy's http server, the proxy's http client, or the upstream server) don't ask for the socket to be kept alive, then the connection will be closed.