Skip to content

Fix unref timer parent #64490 - #64491

Open
Shivay-98 wants to merge 2 commits into
nodejs:mainfrom
Shivay-98:fix-unref-timer-parent
Open

Fix unref timer parent #64490#64491
Shivay-98 wants to merge 2 commits into
nodejs:mainfrom
Shivay-98:fix-unref-timer-parent

Conversation

@Shivay-98

Copy link
Copy Markdown

Summary

Socket.prototype._unrefTimer() traverses the _parent chain using
for (let s = this; s !== null; s = s._parent).

If _parent becomes undefined, the loop performs one additional
iteration and attempts to access undefined[kTimeout], resulting in:

TypeError: Cannot read properties of undefined (reading 'Symbol(timeout)')

Replace the strict null check with a nullish check (s != null) so
the traversal terminates for both null and undefined.

A regression test has been added to cover this case.

Fixes: #64490

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Jul 14, 2026
@aduh95

aduh95 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Can you remove the additional commit and fix the failing test? Also, the commit should have the Signed-off-by trailer

@marco1991layker-code

This comment was marked as low quality.

@marco1991layker-code marco1991layker-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Each property is an array containing all values received for that header.

@marco1991layker-code marco1991layker-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1

Comment thread lib/net.js
haggholm pushed a commit to hightouchio/node that referenced this pull request Jul 21, 2026
The fix and approach are from nodejs#64491 by Shivay-98; this reopens it to
get it landed, since the original stalled awaiting requested changes.

`Socket.prototype._unrefTimer` and `Socket.prototype._destroy` both walk
the `_parent` chain with a strict `!== null` check. During connection
teardown a socket's `_parent` can be left `undefined` (for example a TLS
socket layered over another stream), so the loop steps onto `undefined`
and reads a property off it, throwing a TypeError:

    Cannot read properties of undefined (reading 'Symbol(timeout)')

from an uncaught I/O callback and crashing the process.

Using a nullish (`!= null`) check terminates the walk on both `null` and
`undefined`.

[petter@hightouch.io: apply the same fix to the identical loop in
`_destroy`, which the original regression test already exercised via
`destroy()`; add direct unit coverage for both paths.]

Fixes: nodejs#64490
Refs: nodejs#64491

Signed-off-by: Petter Häggholm <petter@hightouch.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error on Socket unref: Cannot read properties of undefined (reading 'Symbol(timeout)')

4 participants