Skip to content

Commit fa3b428

Browse files
committed
http: align destroy w streams
Streams that are prematurely destroyed without error through .destroy() do usually not emit an error. Align ClientRequest with this behavior.
1 parent 28fae8b commit fa3b428

3 files changed

Lines changed: 3 additions & 21 deletions

File tree

‎lib/_http_client.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ function _destroy(req, socket, err) {
375375
socket.destroy(err);
376376
} else {
377377
socket.emit('free');
378-
if (!req.aborted && !err) {
379-
err = connResetException('socket hang up');
380-
}
381378
if (err) {
382379
req.emit('error', err);
383380
}
@@ -427,7 +424,7 @@ function socketCloseListener() {
427424
res.emit('close');
428425
}
429426
} else {
430-
if (!req.socket._hadError) {
427+
if (!req.destroyed && !req.socket._hadError) {
431428
// This socket error fired before we started to
432429
// receive a response. The error needs to
433430
// fire on the request.

‎test/parallel/test-http-client-abort-keep-alive-queued-tcp-socket.js‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ for (const destroyer of ['destroy', 'abort']) {
2929
const req = http.get({ agent, port }, common.mustNotCall());
3030
req[destroyer]();
3131

32-
if (destroyer === 'destroy') {
33-
req.on('error', common.mustCall((err) => {
34-
assert.strictEqual(err.code, 'ECONNRESET');
35-
}));
36-
} else {
37-
req.on('error', common.mustNotCall());
38-
}
32+
req.on('error', common.mustNotCall());
3933

4034
http.get({ agent, port }, common.mustCall((res) => {
4135
res.resume();

‎test/parallel/test-http-client-close-event.js‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,15 @@ const common = require('../common');
55
// event when a request is made and the socket is closed before we started to
66
// receive a response.
77

8-
const assert = require('assert');
98
const http = require('http');
109

1110
const server = http.createServer(common.mustNotCall());
1211

1312
server.listen(0, common.mustCall(() => {
1413
const req = http.get({ port: server.address().port }, common.mustNotCall());
15-
let errorEmitted = false;
16-
17-
req.on('error', common.mustCall((err) => {
18-
errorEmitted = true;
19-
assert.strictEqual(err.constructor, Error);
20-
assert.strictEqual(err.message, 'socket hang up');
21-
assert.strictEqual(err.code, 'ECONNRESET');
22-
}));
2314

15+
req.on('error', common.mustNotCall());
2416
req.on('close', common.mustCall(() => {
25-
assert.strictEqual(errorEmitted, true);
2617
server.close();
2718
}));
2819

0 commit comments

Comments
 (0)