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

πŸ› Bug Report β€” Response remains open after body is flushed (for ~5s) #1734

Closed
2 tasks
RamIdeas opened this issue Feb 27, 2024 · 1 comment
Closed
2 tasks

Comments

@RamIdeas
Copy link
Contributor

As shown in this comment and this comment, workerd seems to hold the response open for roughly 5 seconds after the data is fully flushed.

By default, curl will wait to receive the number of bytes specified in the Content-Length response header and stop reading the response. By setting the --ignore-content-length flag, you can force curl to wait for the response to be closed. This seems to take roughly 5 seconds longer than when the flag is not set.

This was noticed because tools like ab have a different default. I need to check what the default is in browsers.

I'm short for time right now, but I will (likely next week) follow up with:

  • Do browsers wait for the response to close or the content-length? (I suspect the former but I will check)
  • A workerd-only repro with capnp config
@kentonv
Copy link
Member

kentonv commented Feb 28, 2024

This is working as intended. HTTP/1.1 supports connection reuse: after a request and response have completed, another request can begin on the same connection. By default, KJ HTTP servers give the client 5 seconds (kj::HttpServerSettings::pipelineTimeout) to start another request. After that it closes the connection in order to avoid having an excessive number of idle connections open.

A client must consider the HTTP response complete upon reaching Content-Length (or the final empty chunk of Transfer-Encoding: chunked). It would in fact be a severe error (possible security vulnerability) for the client to treat any bytes after this point as being part of the response. In any case, it is not expected that the connection be closed at the end of a response -- unless the response had neither Content-Length nor Transfer-Encoding headers, in which case EOF is the only way to indicate the end of the response, but this is historical behavior from HTTP/1.0 which HTTP/1.1 implementations rarely use.

@kentonv kentonv closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
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

No branches or pull requests

2 participants