Mongoose prematurely closes connections when the second request in a pipeline is invalid #2592
Description
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
- Start the
http-server
example. - 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
- 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?