Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Aug 21, 2023

Conversation

minrk
Copy link
Member

@minrk minrk commented Aug 17, 2023

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
Copy link
Member

consideRatio commented Aug 17, 2023

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
Copy link
Member Author

minrk commented Aug 18, 2023

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.

  • the client's response from the proxy will have Connection: close if any of the following are true:
    • the client doesn't request keep-alive (keep-alive is the default in http 1.1)
    • the proxy server doesn't specify keepAlive support (changed in this PR)
    • the upstream response sets Connection: close
  • and that upstream response has again the same logic, where the client must request keepalive (changed in this PR), and the upstream server must support it, which tornado does.

@minrk minrk force-pushed the keep-alive branch 3 times, most recently from ea3f6cd to 84abbae Compare August 18, 2023 09:18
@consideRatio consideRatio changed the title Enable keep-alive Enable keep-alive - --keep-alive-timeout added, defaulting to 5000ms Aug 21, 2023
@consideRatio consideRatio changed the title Enable keep-alive - --keep-alive-timeout added, defaulting to 5000ms Enable keep-alive, --keep-alive-timeout flag added (default: 5000ms) Aug 21, 2023
Copy link
Member

@consideRatio consideRatio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for helping me understand this better, I think I understand it well enough to dare agree this makes sense and merge given that this LGTM!

@consideRatio consideRatio merged commit 094ff57 into jupyterhub:main Aug 21, 2023
10 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants