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: ignore multiple abort #28706

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
6 changes: 4 additions & 2 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,12 @@ ClientRequest.prototype._implicitHeader = function _implicitHeader() {
};

ClientRequest.prototype.abort = function abort() {
if (!this.aborted) {
process.nextTick(emitAbortNT.bind(this));
if (this.aborted) {
return;
}

this.aborted = true;
process.nextTick(emitAbortNT.bind(this));

// If we're aborting, we don't care about any more response data.
if (this.res) {
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-http-client-abort2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const server = http.createServer(common.mustCall((req, res) => {
server.listen(0, common.mustCall(() => {
const options = { port: server.address().port };
const req = http.get(options, common.mustCall((res) => {
res._dump = common.mustCall(res._dump.bind(res));
res.on('data', (data) => {
req.abort();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make this a separate test rather than modifying the existing test? My concern is that the existing test is such a straightforward one and this kind of makes it less obvious what's going on. (There's no comment explaining why req.abort() is being called twice. But also wouldn't we want a test where it is only called once?)

req.abort();
server.close();
});
Expand Down