Skip to content

fix: replace deprecated 'aborted' event with 'close' on IncomingMessage#4579

Open
sapirbaruch wants to merge 2 commits into
hapijs:masterfrom
sapirbaruch:fix/replace-deprecated-aborted-event
Open

fix: replace deprecated 'aborted' event with 'close' on IncomingMessage#4579
sapirbaruch wants to merge 2 commits into
hapijs:masterfrom
sapirbaruch:fix/replace-deprecated-aborted-event

Conversation

@sapirbaruch
Copy link
Copy Markdown

The 'aborted' event on http.IncomingMessage was deprecated in Node.js v17 and no longer fires in v24+. As a result, Request.active() always returns true because _eventContext.request is never set to null on client disconnects.

The fix replaces req.on('aborted', ...) with req.on('close', ...) and guards the abort logic with a res.writableEnded check — the same guard used by the existing res.on('close') handler — to distinguish a premature client disconnect from a normal connection teardown.

Fixes #4575.

@damusix
Copy link
Copy Markdown
Contributor

damusix commented May 19, 2026

@sapirbaruch Can you please add tests for this?

Adds a test verifying that request.active() returns false when the
client closes the connection before a response is sent. The test uses
Net.connect so it works regardless of hostname resolution, and polls
active() directly without relying on the 'disconnect' event.

Covers the Node.js v24+ path where IncomingMessage 'aborted' is gone.
@sapirbaruch
Copy link
Copy Markdown
Author

Added a regression test in test/request.js that verifies request.active() returns false when the client closes the connection before a response is sent.

The test uses Net.connect to make an actual TCP connection to localhost so it works regardless of hostname resolution, and polls active() directly without depending on the disconnect event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The abort event on nodejs is deprecated

2 participants