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 server returns 400 status code for valid request on keepalive connection after an error was caught by a domain #24953

Closed
dragosnicolae opened this issue Dec 11, 2018 · 6 comments
Labels
domain Issues and PRs related to the domain subsystem. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. http Issues or PRs related to the http subsystem.

Comments

@dragosnicolae
Copy link

dragosnicolae commented Dec 11, 2018

  • Version: 10.13.0
  • 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.

@dragosnicolae
Copy link
Author

Tested on node 8.11.3 and this does not happen, both requests end with 500 status code.

@bnoordhuis bnoordhuis added http Issues or PRs related to the http subsystem. domain Issues and PRs related to the domain subsystem. labels Jan 23, 2019
@bnoordhuis
Copy link
Member

It sounds like #25456 may be a duplicate of this issue, or at least is related.

@BridgeAR
Copy link
Member

BridgeAR commented Jan 2, 2020

This is still reproducible on master. Seems like this was fixed on v8.x only.

@BridgeAR
Copy link
Member

BridgeAR commented Jan 2, 2020

@misterdjules PTAL. I think you might have a fix for this.

@jasnell jasnell added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Jun 26, 2020
@mmomtchev
Copy link
Contributor

Still reproducible on Node 12 but not on Node 14/master

@BethGriggs
Copy link
Member

I believe this was fixed in Node.js v12.19.0 (#35401)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain Issues and PRs related to the domain subsystem. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants