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

Mongoose prematurely closes connections when the second request in a pipeline is invalid #2592

Closed
kenballus opened this issue Jan 29, 2024 · 0 comments

Comments

@kenballus
Copy link

Describe the bug

From RFC 9112, section 9.6:

A server that receives a "close" connection option MUST initiate closure of the connection (see below) after it sends the final response to the request that contained the "close" connection option. The server SHOULD send a "close" connection option in its final response on that connection. The server MUST NOT process any further requests received on that connection.

When Mongoose receives a pipeline with a request containing Connection: close, followed by an invalid request, it closes the connection prematurely, without responding to the first request in the pipeline.

To Reproduce

  1. Start the http-server example.
  2. Send it a pipeline consisting of a valid request with Connection: close set, followed by an invalid request:
printf 'GET / HTTP/1.1\r\nConnection: close\r\n\r\nInvalid\r\n\r\n' | nc localhost 8000
  1. Observe that the server does not respond, and immediately closes the connection,

Expected behavior

The server should respond to the first request, and then close the connection.

Logs

17e1fd9 2 main.c:32:cb                  GET / 200 2257
17e1fd9 1 mongoose.c:1359:mg_error      2 5 HTTP parse, 48 bytes
0000   47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a   GET / HTTP/1.1..
17e1fd9 2 main.c:32:cb                  GET / 200 2257

Weirdly, the log indicates that the GET request was processed twice. This might be indicative of a deeper problem?

@cpq cpq closed this as completed in 2419f02 Feb 13, 2024
cpq added a commit that referenced this issue Feb 13, 2024
Fix #2592: do not close pipelined connection prematurely
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

1 participant