Skip to content

http server returns 400 status code for valid request on keepalive connection after an error was caught by a domain #24953

Description

@dragosnicolae
  • 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.

Activity

  1. dragosnicolae commented on Dec 11, 2018

    @dragosnicolae
    Author

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

  2. added
    httpIssues and PRs related to the http subsystem.
    domainIssues and PRs related to the domain subsystem.
    on Jan 23, 2019
  3. bnoordhuis commented on Jan 23, 2019

    @bnoordhuis
    Member

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

  4. BridgeAR commented on Jan 2, 2020

    @BridgeAR
    Member

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

  5. BridgeAR commented on Jan 2, 2020

    @BridgeAR
    Member

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

  6. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Jun 26, 2020
  7. mmomtchev commented on Oct 9, 2020

    @mmomtchev
    Contributor

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

  8. BethGriggs commented on Feb 17, 2022

    @BethGriggs
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    domainIssues and PRs related to the domain subsystem.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions