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: emit ECONNRESET if no 'aborted' listener #28677

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,9 @@ will be emitted in the following order:
* `'data'` any number of times, on the `res` object
* (`req.abort()` called here)
* `'abort'`
* `'aborted'` on the `res` object
* `'aborted'` on the `res` object if `'aborted'` listener exists, otherwise
`'error'` with an error with message `'Error: aborted'` and code
`'ECONNRESET'`
* `'close'`
* `'end'` on the `res` object
* `'close'` on the `res` object
Expand Down
4 changes: 3 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ function socketCloseListener() {
// Socket closed before we emitted 'end' below.
if (!res.complete) {
res.aborted = true;
res.emit('aborted');
if (!res.emit('aborted')) {
res.emit('error', connResetException('aborted'));
}
}
req.emit('close');
if (res.readable) {
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-domain-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const server = http.createServer((req, res) => {
req.on('response', (res) => {
// Add the response object to the C domain
c.add(res);
res.on('aborted', common.mustCall());
res.pipe(process.stdout);
});

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-abort-stream-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const server = http.createServer(common.mustCall((req, res) => {

server.listen(0, () => {
const res = common.mustCall((res) => {
res.on('error', common.mustCall());
res.on('data', (chunk) => {
size += chunk.length;
assert(!req.aborted, 'got data after abort');
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-agent-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const server = http.createServer(mustCall((req, res) => {
server.listen(0, mustCall(() => {
const req = http.get({
port: server.address().port
}, mustCall(() => {
}, mustCall((res) => {
res.on('error', mustCall());
const { socket } = req;
socket.emit('agentRemove');
strictEqual(socket._httpMessage, req);
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-catch-uncaughtexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const server = http.createServer(function(req, res) {
}).listen(0, function() {
http.get({ port: this.address().port }, function(res) {
res.resume();
res.on('error', common.mustCall());
throw new Error('get did fail');
}).on('close', function() {
server.close();
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-client-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ server.listen(0, common.mustCall(() => {
requests.push(
http.get(options, common.mustCall((res) => {
res.resume();
res.on('error', common.mustCall());
reqCountdown.dec();
})));
}
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-client-aborted-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ server.listen(0, common.mustCall(function() {
server.close();
serverRes.destroy();
res.on('aborted', common.mustCall());
res.on('error', common.mustNotCall());
}));
}));
23 changes: 23 additions & 0 deletions test/parallel/test-http-client-response-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');

let serverRes;
const server = http.Server(function(req, res) {
res.write('Part of my res.');
serverRes = res;
});

server.listen(0, common.mustCall(function() {
http.get({
port: this.address().port,
headers: { connection: 'keep-alive' }
}, common.mustCall(function(res) {
server.close();
serverRes.destroy();
res.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ECONNRESET');
}));
}));
}));
1 change: 1 addition & 0 deletions test/parallel/test-http-flush-response-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ server.listen(0, common.localhostIPv4, function() {
function onResponse(res) {
assert.strictEqual(res.headers.foo, 'bar');
res.destroy();
res.on('error', common.mustCall());
server.close();
}
});
1 change: 1 addition & 0 deletions test/parallel/test-http-response-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const http = require('http');
res.on('data', common.mustCall(() => {
res.destroy();
}));
res.on('error', common.mustCall());
res.on('close', common.mustCall(() => {
server.close();
}));
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-https-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ server.listen(0, () => {

const req = https.request(requestOptions, (res) => {
res.on('data', () => {});
res.on('aborted', common.mustCall());
setImmediate(shutdown);
});
req.end();
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const { promisify } = require('util');

req.end();
req.on('response', (res) => {
res.on('aborted', common.mustCall());
setImmediate(() => {
res.destroy();
server.close();
Expand Down