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

test: fix http-agent-destroyed-socket cb not firing #20006

Closed
Changes from 1 commit
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
16 changes: 2 additions & 14 deletions test/parallel/test-http-agent-destroyed-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,9 @@ const server = http.createServer(common.mustCall((req, res) => {
request1.socket.on('close', common.mustCall());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I guess this is redundant now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point. Will fix in the morning. Thanks!

response.resume();
response.on('end', common.mustCall(() => {
//
// THE IMPORTANT PART
//
// It is possible for the socket to get destroyed and other work
// to run before the 'close' event fires because it happens on
// nextTick. This example is contrived because it destroys the
// socket manually at just the right time, but at Voxer we have
// seen cases where the socket is destroyed by non-user code
// then handed out again by an agent *before* the 'close' event
// is triggered.
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment is no longer relevant hence the removal.

request1.socket.destroy();

// TODO(jasnell): This close event does not appear to be triggered.
// is it necessary?
response.once('close', () => {
response.socket.once('close', common.mustCall(() => {
// assert request2 was removed from the queue
assert(!agent.requests[key]);
process.nextTick(() => {
Expand All @@ -70,7 +58,7 @@ const server = http.createServer(common.mustCall((req, res) => {
assert.notStrictEqual(request1.socket, request2.socket);
assert(!request2.socket.destroyed, 'the socket is destroyed');
});
});
}));
}));
}));

Expand Down