Skip to content

net: handle undefined parent in _unrefTimer and _destroy#64644

Open
haggholm wants to merge 1 commit into
nodejs:mainfrom
hightouchio:fix/net-unref-timer-parent-chain
Open

net: handle undefined parent in _unrefTimer and _destroy#64644
haggholm wants to merge 1 commit into
nodejs:mainfrom
hightouchio:fix/net-unref-timer-parent-chain

Conversation

@haggholm

Copy link
Copy Markdown

The fix and approach are from #64491 by @Shivay-98; opening from a fresh branch to land it, since that PR stalled awaiting the requested changes (unrelated commit dropped, failing test addressed, Signed-off-by added).

Socket.prototype._unrefTimer and Socket.prototype._destroy both walk the socket _parent chain with a strict !== null check. When teardown leaves a socket's _parent as undefined (for example a TLS socket layered over another stream), the loop steps onto undefined and throws

TypeError: Cannot read properties of undefined (reading 'Symbol(timeout)')
    at TLSSocket._unrefTimer (node:net)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons)

from an uncaught I/O callback, crashing the process. Switching both loops to a nullish != null check stops the walk on undefined as well.

The original PR fixed only _unrefTimer; its regression test also calls destroy(), which hits the same unpatched loop in _destroy, so that path is fixed and covered here too.

Fixes: #64490
Refs: #64491

Checklist
  • make -j4 test (UNIX) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

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

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (ed63b19) to head (6b91d30).
⚠️ Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64644      +/-   ##
==========================================
- Coverage   92.01%   90.14%   -1.88%     
==========================================
  Files         381      741     +360     
  Lines      170167   242095   +71928     
  Branches    26075    45552   +19477     
==========================================
+ Hits       156585   218239   +61654     
- Misses      13291    15364    +2073     
- Partials      291     8492    +8201     
Files with missing lines Coverage Δ
lib/net.js 94.37% <100.00%> (+3.37%) ⬆️

... and 514 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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>
@haggholm
haggholm force-pushed the fix/net-unref-timer-parent-chain branch from 6b91d30 to ae8a326 Compare July 21, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)')

3 participants