Skip to content

fix: reuse parser WeakRef for timeout callbacks#5125

Merged
mcollina merged 2 commits intonodejs:mainfrom
trivikr:reuse-parser-weakref-2
Apr 27, 2026
Merged

fix: reuse parser WeakRef for timeout callbacks#5125
mcollina merged 2 commits intonodejs:mainfrom
trivikr:reuse-parser-weakref-2

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented Apr 27, 2026

This relates to...

N/A

Rationale

Parser#setTimeout() created a new WeakRef each time it replaced a timeout callback.
The parser instance is stable for the socket lifetime, so the same WeakRef can be reused instead of allocating a new one for every timeout replacement.

Changes

  • Store a single parser WeakRef on Parser construction.
  • Reuse that WeakRef for both fast timer and native timer timeout callbacks.

Features

N/A

Bug Fixes

Avoid repeated WeakRef allocations when replacing parser timeout callbacks.

Breaking Changes and Deprecations

N/A

Status

Assisted-by: openai:gpt-5.5

Assisted-by: openai:gpt-5.5
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.13%. Comparing base (efae3da) to head (fd4b3da).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5125      +/-   ##
==========================================
- Coverage   93.14%   93.13%   -0.01%     
==========================================
  Files         110      110              
  Lines       35908    36105     +197     
==========================================
+ Hits        33446    33627     +181     
- Misses       2462     2478      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Comment thread test/client-timeout.js Outdated

t.strictEqual(weakRefCount, 1)
} finally {
global.WeakRef = OriginalWeakRef
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.

instead of a try/catch, use t.after

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in fd4b3da

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit ead8a6b into nodejs:main Apr 27, 2026
34 of 35 checks passed
@trivikr trivikr deleted the reuse-parser-weakref-2 branch April 27, 2026 12:48
mcollina pushed a commit that referenced this pull request Apr 29, 2026
@github-actions github-actions Bot mentioned this pull request May 1, 2026
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.

3 participants