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

@haggholmhaggholm commented Jul 21, 2026

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-botnodejs-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

codecovBot 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 (0fff075).
⚠️ Report is 248 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #64644 +/- ##
==========================================
- Coverage 92.01% 90.14% -1.87% 
==========================================
Files 381 741 +360 Lines 170167 242137 +71970 Branches 26075 45568 +19493 ==========================================
+ Hits 156585 218286 +61701 - Misses 13291 15368 +2077 - Partials 291 8483 +8192 
Files with missing linesCoverage Δ
lib/net.js94.37% <100.00%> (+3.37%)⬆️

... and 513 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.

@haggholm
haggholmforce-pushed the fix/net-unref-timer-parent-chain branch from 6b91d30 to ae8a326CompareJuly 21, 2026 16:44
@haggholm

Copy link
Copy Markdown
Author

Cc. @aduh95 who was active in the original PR.

Note: I've never contributed to Node and basically do not know what I am doing.

Comment threadlib/net.js Outdated
@pimterry

Copy link
Copy Markdown
Member

Note: I've never contributed to Node and basically do not know what I am doing.

Thanks for the PR @haggholm, no worries, this looks good to me and all going in the right direction. Very helpful picking up stalled work like this. I have a minor comment here that it'd be nice to clean up (you can just push another commit and they'll be squashed together at merge automatically) but otherwise everything looks great.

Don't worry too much about the test-internet failure, I strongly suspect something flaky is going on there... Could be us, could be github actions, hard to say.

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
haggholmforce-pushed the fix/net-unref-timer-parent-chain branch from ae8a326 to 0fff075CompareJuly 21, 2026 21:06
@pimterrypimterry added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jul 22, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@pimterry

Copy link
Copy Markdown
Member

Don't worry too much about the test-internet failure, I strongly suspect something flaky is going on there... Could be us, could be github actions, hard to say.

More specifically, I see now it's been broken on main but will be fixed by #64624 imminently, we'll just need to wait until that's merged then rebase this.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Ethan-ArrowoodEthan-Arrowood added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@pimterry

Copy link
Copy Markdown
Member

More specifically, I see now it's been broken on main but will be fixed by #64624 imminently, we'll just need to wait until that's merged then rebase this.

#64624 has now been merged to fix test-internet. If you rebase and force push, this should be good to go.

@lpinca

lpinca commented Jul 24, 2026

Copy link
Copy Markdown
Member

My only observation is that _parent is a "private" property so its value should not be changed by user code.

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

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.needs-ciPRs that need a full CI run.netIssues 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)')

7 participants

@haggholm@nodejs-github-bot@pimterry@lpinca@mcollina@Ethan-Arrowood@Shivay-98