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

http - keepalive timeout hint #34560

Closed
ronag opened this issue Jul 30, 2020 · 3 comments
Closed

http - keepalive timeout hint #34560

ronag opened this issue Jul 30, 2020 · 3 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@ronag
Copy link
Member

ronag commented Jul 30, 2020

Having the server send a keep-alive header to the client with keep alive timeout hints would be useful.

In http 1.1 persistent connection protocol there is a timing race where the client sends the request and then the server kills the connection (due to inactivity) before receiving the client's request.

Currently the only way to mitigate this is to ensure the client has a shorter idle timeout than the server. Which currently is only guesswork unless you know the exact server settings/behavior. Providing a hint for the client would help alleviate this problem.

nginx does this:

From looking at nginx docs, it seems an header that is send from the server to the client.

From http://nginx.org/en/docs/http/ngx_http_core_module.html

The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.

The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

Originally posted by @mcollina in nodejs/undici#273 (comment)

A follow up for this would be to have the http client implement the corresponding functionality (i.e. reduce idle timeout based on hint).

@ronag ronag added the http Issues or PRs related to the http subsystem. label Jul 30, 2020
@ronag
Copy link
Member Author

ronag commented Jul 30, 2020

@nodejs/http @nodejs/web-server-frameworks

@mcollina
Copy link
Member

I think implementing this on both sides (client and server) would be very handy.

Do we have a clue if other browsers/clients support this header?

@ronag
Copy link
Member Author

ronag commented Jul 30, 2020

Mozilla seems to support it.

ronag added a commit to nxtedition/node that referenced this issue Jul 30, 2020
In http 1.1 persistent connection protocol there is a timing race where the
client sends the request and then the server kills the connection
(due to inactivity) before receiving the client's request.

By providing a keep-alive header it is possible to provide the client a
hint of when idle timeout would occur and avoid the race.

Fixes: nodejs#34560
@ronag ronag closed this as completed in 849d9e7 Aug 1, 2020
codebytere pushed a commit that referenced this issue Aug 5, 2020
In http 1.1 persistent connection protocol there is a
timing race where the client sends the request and then
the server kills the connection (due to inactivity)
before receiving the client's request.

By providing a keep-alive header it is possible to provide
the client a hint of when idle timeout would occur and
avoid the race.

Fixes: #34560

PR-URL: #34561
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
addaleax pushed a commit that referenced this issue Sep 22, 2020
In http 1.1 persistent connection protocol there is a
timing race where the client sends the request and then
the server kills the connection (due to inactivity)
before receiving the client's request.

By providing a keep-alive header it is possible to provide
the client a hint of when idle timeout would occur and
avoid the race.

Fixes: #34560

PR-URL: #34561
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
addaleax pushed a commit that referenced this issue Sep 22, 2020
In http 1.1 persistent connection protocol there is a
timing race where the client sends the request and then
the server kills the connection (due to inactivity)
before receiving the client's request.

By providing a keep-alive header it is possible to provide
the client a hint of when idle timeout would occur and
avoid the race.

Fixes: #34560

PR-URL: #34561
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants