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: double error emitted after HPE_INVALID_CONSTANT #40242

Closed
mcollina opened this issue Sep 28, 2021 · 4 comments
Closed

http: double error emitted after HPE_INVALID_CONSTANT #40242

mcollina opened this issue Sep 28, 2021 · 4 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@mcollina
Copy link
Member

The following snipped could cause an internal assertion to fail and an error to be emitted twice:

const https = require('https');
const fs = require('fs');
const path = require('path');

var file = fs.createWriteStream(path.resolve(__dirname, "test"));
https.get(URL, function(response) {
    response.pipe(file);
    file.on("finish", function() {
        file.close();
        console.log("Download complete");
    });
}).on("error", function(err) {
    console.error(err);
});
Error: Parse Error: Expected HTTP/
    at HTTPParser.execute (<anonymous>)
    at TLSSocket.socketOnData (_http_client.js:509:22)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.Readable.read (internal/streams/readable.js:519:10)
    at TLSSocket.Socket.read (net.js:625:39)
    at flow (internal/streams/readable.js:992:34)
    at resume_ (internal/streams/readable.js:973:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  bytesParsed: 5381,
  code: 'HPE_INVALID_CONSTANT',
  reason: 'Expected HTTP/',
  rawPacket: <Buffer 76 5e f0 68 d0 0c 11 d7 50 8f 67 2e 18 c8 b3 a6 ac c8 75 70 2b e3 65 26 5d e9 b5 1f 6e 62 2b 88 87 15 0e 2f 14 4b 7d 90 33 6a 5a 18 06 bf 74 86 cf 6c ... 16334 more bytes>
}
internal/assert.js:14
    throw new ERR_INTERNAL_ASSERTION(message);
    ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at assert (internal/assert.js:14:11)
    at TLSSocket.socketOnData (_http_client.js:507:3)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.Readable.read (internal/streams/readable.js:519:10)
    at TLSSocket.Socket.read (net.js:625:39)
    at flow (internal/streams/readable.js:992:34)
    at resume_ (internal/streams/readable.js:973:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'ERR_INTERNAL_ASSERTION'
}

v14.16.0 linux arm

Originally posted by @terreng in #35384 (comment)

@mcollina
Copy link
Member Author

WDYT @ronag?

@mcollina mcollina added the http Issues or PRs related to the http subsystem. label Sep 28, 2021
@ronag
Copy link
Member

ronag commented Sep 28, 2021

I think this is one of those we've been struggling with at undici as well. The server might be sending more data than is advertised in the content-length header. I don't know of any good solution to this problem.

@mcollina
Copy link
Member Author

I'm referring on the fact that we are not removing the listener for 'data' in https://github.com/nodejs/node/blob/master/lib/_http_client.js#L488-L494.

@ronag
Copy link
Member

ronag commented Sep 28, 2021

We should probably remove the listener or add a socket.destroyed check.

mcollina added a commit to mcollina/node that referenced this issue Sep 28, 2021
There might be the case of some more data coming through after
the parser has returned an error and we have destroyed the socket.
We should also be removing the 'data' event handler.

Fixes: nodejs#40242
targos pushed a commit that referenced this issue Oct 4, 2021
There might be the case of some more data coming through after
the parser has returned an error and we have destroyed the socket.
We should also be removing the 'data' event handler.

Fixes: #40242

PR-URL: #40244
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants