You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
http server returns 400 status code for valid request on keepalive connection after an error was caught by a domain #24953
Platform: Linux themachine.novalocal 3.10.0-862.14.4.el7.x86_64 deps: update openssl to 1.0.1j #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
If an error is thrown while handling a request and then it is caught by an error domain, the second request coming on the same connection is not parsed correctly and the server returns 400 Bad Request.
I managed to reproduce this using a simple example. Server code:
'use strict';
var ed = require('domain');
var http = require('http');
var count = 0;
var server = http.createServer(function(request, response) {
var d = ed.createDomain();
d.on('error', function() {
console.log("request", count++);
response.statusCode = 500;
response.end();
});
d.enter();
throw new Error("Something wrong happened.");
d.exit();
});
server.listen(8092, "127.0.0.1", function() {
console.log("connected");
});
Make the requests:
# curl -v 'http://127.0.0.1:8092' 'http://127.0.0.1:8092'
* About to connect() to 127.0.0.1 port 8092 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8092 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:8092
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 11 Dec 2018 09:49:43 GMT
< Connection: keep-alive
< Content-Length: 0
<
* Connection #0 to host 127.0.0.1 left intact
* Found bundle for host 127.0.0.1: 0x2283ec0
* Re-using existing connection! (#0) with host 127.0.0.1
* Connected to 127.0.0.1 (127.0.0.1) port 8092 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:8092
> Accept: */*
>
< HTTP/1.1 400 Bad Request
* no chunk, no close, no size. Assume close to signal end
<
* Closing connection 0
From what I found, the parser returns a HPE_CB_headers_complete error code. Most probably, the parser's internal state gets messed up or does not get to update when the error is thrown.
Activity
dragosnicolae commentedon Dec 11, 2018
Tested on node 8.11.3 and this does not happen, both requests end with 500 status code.
bnoordhuis commentedon Jan 23, 2019
It sounds like #25456 may be a duplicate of this issue, or at least is related.
BridgeAR commentedon Jan 2, 2020
This is still reproducible on master. Seems like this was fixed on v8.x only.
BridgeAR commentedon Jan 2, 2020
@misterdjules PTAL. I think you might have a fix for this.
mmomtchev commentedon Oct 9, 2020
Still reproducible on Node 12 but not on Node 14/master
BethGriggs commentedon Feb 17, 2022
I believe this was fixed in Node.js v12.19.0 (#35401)