Skip to content

Commit 0796f0e

Browse files
committed
Revert "http: fix test where aborted should not be emitted"
This reverts commit 461bf36. PR-URL: #28699 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent c3caf21 commit 0796f0e

6 files changed

+10
-60
lines changed

doc/api/http.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ added: v0.3.8
541541
-->
542542

543543
Marks the request as aborting. Calling this will cause remaining data
544-
in the response to be dropped and the socket to be destroyed. After
545-
calling this method no further errors will be emitted.
544+
in the response to be dropped and the socket to be destroyed.
546545

547546
### request.aborted
548547
<!-- YAML
@@ -2143,6 +2142,8 @@ will be emitted in the following order:
21432142
* `'socket'`
21442143
* (`req.abort()` called here)
21452144
* `'abort'`
2145+
* `'error'` with an error with message `'Error: socket hang up'` and code
2146+
`'ECONNRESET'`
21462147
* `'close'`
21472148

21482149
If `req.abort()` is called after the response is received, the following events

lib/_http_client.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ function socketCloseListener() {
374374
// receive a response. The error needs to
375375
// fire on the request.
376376
req.socket._hadError = true;
377-
if (!req.aborted) {
378-
req.emit('error', connResetException('socket hang up'));
379-
}
377+
req.emit('error', connResetException('socket hang up'));
380378
}
381379
req.emit('close');
382380
}
@@ -402,9 +400,7 @@ function socketErrorListener(err) {
402400
// For Safety. Some additional errors might fire later on
403401
// and we need to make sure we don't double-fire the error event.
404402
req.socket._hadError = true;
405-
if (!req.aborted) {
406-
req.emit('error', err);
407-
}
403+
req.emit('error', err);
408404
}
409405

410406
// Handle any pending data
@@ -438,9 +434,7 @@ function socketOnEnd() {
438434
// If we don't have a response then we know that the socket
439435
// ended prematurely and we need to emit an error on the request.
440436
req.socket._hadError = true;
441-
if (!req.aborted) {
442-
req.emit('error', connResetException('socket hang up'));
443-
}
437+
req.emit('error', connResetException('socket hang up'));
444438
}
445439
if (parser) {
446440
parser.finish();
@@ -463,9 +457,7 @@ function socketOnData(d) {
463457
freeParser(parser, req, socket);
464458
socket.destroy();
465459
req.socket._hadError = true;
466-
if (!req.aborted) {
467-
req.emit('error', ret);
468-
}
460+
req.emit('error', ret);
469461
} else if (parser.incoming && parser.incoming.upgrade) {
470462
// Upgrade (if status code 101) or CONNECT
471463
var bytesParsed = ret;

test/parallel/test-http-client-aborted.js

-23
This file was deleted.

test/parallel/test-http-client-no-error-after-aborted.js

-21
This file was deleted.

test/parallel/test-http-client-timeout-on-connect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => {
2323
}));
2424
}));
2525
req.on('timeout', common.mustCall(() => req.abort()));
26-
req.on('abort', common.mustCall(() => {
26+
req.on('error', common.mustCall((err) => {
27+
assert.strictEqual(err.message, 'socket hang up');
2728
server.close();
2829
}));
2930
}));

test/parallel/test-http-writable-true-after-close.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const server = createServer(common.mustCall((req, res) => {
3434
}));
3535
}).listen(0, () => {
3636
external = get(`http://127.0.0.1:${server.address().port}`);
37-
external.on('abort', common.mustCall(() => {
37+
external.on('error', common.mustCall(() => {
3838
server.close();
3939
internal.close();
4040
}));

0 commit comments

Comments
 (0)