diff --git a/doc/contributing/using-devcontainer.md b/doc/contributing/using-devcontainer.md index bd118d03d027d5..77483b87c4abb6 100644 --- a/doc/contributing/using-devcontainer.md +++ b/doc/contributing/using-devcontainer.md @@ -2,7 +2,7 @@ Node.js publishes a [nightly image on DockerHub](https://hub.docker.com/r/nodejs/devcontainer) for [Dev Containers](https://containers.dev/) that can be used to spin up a -development container that comes with pre-installed build dependencies and pre-genreated build cache. +development container that comes with pre-installed build dependencies and pre-generated build cache. When you need to test a few changes in the main branch and do not need to change the V8 headers (which is rare), using the nightly image will allow you to compile your diff --git a/lib/_http_client.js b/lib/_http_client.js index d202a28f03502f..9eb3c10547d520 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -752,24 +752,10 @@ function socketErrorListener(err) { debug('SOCKET ERROR:', err.message, err.stack); if (req) { - const res = req.res; - const isUserDestroyError = err === req[kError] || err === res?.errored; - // For Safety. Some additional errors might fire later on // and we need to make sure we don't double-fire the error event. socket._hadError = true; - // Before a response exists, the request itself failed. Once a response - // exists, socket teardown belongs to the IncomingMessage and is finalized - // by socketCloseListener. Preserve errors explicitly used to destroy the - // request or response, which have historically been emitted on the request. - if (!res || isUserDestroyError) { - emitErrorEvent(req, err); - } - - if (res) { - socket.destroy(); - return; - } + emitErrorEvent(req, err); } const parser = socket.parser; diff --git a/test/parallel/test-http-client-complete-response-reset.js b/test/parallel/test-http-client-complete-response-reset.js deleted file mode 100644 index aa9337dbcc5206..00000000000000 --- a/test/parallel/test-http-client-complete-response-reset.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const http = require('http'); - -const BODY = Buffer.alloc(2 * 1024 * 1024); - -const server = http.createServer(common.mustCall((request, response) => { - let received = 0; - - request.on('data', function onData(chunk) { - received += chunk.length; - request.off('data', onData); - request.destroy(); - }); - - response.writeHead(413, { 'content-length': 0 }); - response.end(); - - request.on('end', common.mustNotCall()); - request.on('close', common.mustCall(() => { - assert.strictEqual(request.complete, false); - assert.ok(received > 0); - })); -})); - -server.listen(0, common.mustCall(() => { - let response; - const req = http.request({ - method: 'POST', - port: server.address().port, - headers: { - 'content-type': 'application/json', - 'content-length': BODY.length, - }, - }, common.mustCall((res) => { - response = res; - assert.strictEqual(res.statusCode, 413); - // Deliberately do not consume the response body. A response that has - // already been received should not be followed by a late ClientRequest - // socket error. - req.write(BODY); - req.end(); - })); - - req.on('error', common.mustNotCall()); - req.on('close', common.mustCall(() => { - assert(response); - assert.strictEqual(response.complete, true); - server.close(); - })); - - req.flushHeaders(); -})); diff --git a/test/parallel/test-tls-psk-alpn-callback-exception-handling.js b/test/parallel/test-tls-psk-alpn-callback-exception-handling.js index 31d7802931fb36..0ba55f9153b947 100644 --- a/test/parallel/test-tls-psk-alpn-callback-exception-handling.js +++ b/test/parallel/test-tls-psk-alpn-callback-exception-handling.js @@ -95,10 +95,7 @@ describe('TLS callback exception handling', () => { reject(e); } })); - - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -113,7 +110,7 @@ describe('TLS callback exception handling', () => { }), }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; }); @@ -307,9 +304,6 @@ describe('TLS callback exception handling', () => { } })); - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); await new Promise((res) => server.listen(0, res)); @@ -324,7 +318,7 @@ describe('TLS callback exception handling', () => { }), }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; }); @@ -354,10 +348,7 @@ describe('TLS callback exception handling', () => { reject(e); } })); - - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -368,7 +359,7 @@ describe('TLS callback exception handling', () => { ALPNProtocols: ['http/1.1', 'h2'], }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; }); @@ -397,10 +388,7 @@ describe('TLS callback exception handling', () => { reject(e); } })); - - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -411,7 +399,7 @@ describe('TLS callback exception handling', () => { ALPNProtocols: ['http/1.1'], }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; }); @@ -430,9 +418,7 @@ describe('TLS callback exception handling', () => { const { promise, resolve, reject } = createTestPromise(); - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -474,9 +460,7 @@ describe('TLS callback exception handling', () => { const { promise, resolve, reject } = createTestPromise(); - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -527,10 +511,7 @@ describe('TLS callback exception handling', () => { reject(e); } })); - - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -541,7 +522,7 @@ describe('TLS callback exception handling', () => { rejectUnauthorized: false, }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; }); @@ -574,10 +555,7 @@ describe('TLS callback exception handling', () => { reject(e); } })); - - server.on('secureConnection', () => { - reject(new Error('secureConnection should not fire')); - }); + server.on('secureConnection', common.mustNotCall('secureConnection listener')); await new Promise((res) => server.listen(0, res)); @@ -588,7 +566,7 @@ describe('TLS callback exception handling', () => { rejectUnauthorized: false, }); - client.on('error', () => {}); + client.on('error', common.mustCall()); await promise; });