Skip to content

perf_hooks: do not record timerify entry for async throw#62947

Open
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-42743-timerify-async-throw
Open

perf_hooks: do not record timerify entry for async throw#62947
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-42743-timerify-async-throw

Conversation

@maruthang
Copy link
Copy Markdown

timerify used result.finally(processComplete) for thenables,
which recorded a histogram sample and enqueued a function
PerformanceEntry on async rejection. The sync-throw path never
reached processComplete because the throw happens inside
ReflectApply, so async- and sync-throwing variants of the same
function produced different observable outputs.

Use result.then(onFulfilledTimerified) with no onRejected so
rejections propagate unchanged and processComplete runs only on
fulfillment. Relax the thenable check from finally to then,
since a thenable is only required to implement then.

Fixes: #42743

Note: I was unable to run the test suite locally (no built out/Release/node on this Windows host). Both files pass node --check and lint clean; logic verified by code review and the pre-fix repro confirms current behavior. Looking forward to CI verification.

`timerify` used `result.finally(processComplete)` for thenables,
which recorded a histogram sample and enqueued a `function`
PerformanceEntry on async rejection. The sync-throw path never
reached `processComplete` because the throw happens inside
ReflectApply, so async- and sync-throwing variants of the same
function produced different observable outputs.

Use `result.then(onFulfilledTimerified)` with no onRejected so
rejections propagate unchanged and `processComplete` runs only on
fulfillment. Relax the thenable check from `finally` to `then`,
since a thenable is only required to implement `then`.

Fixes: nodejs#42743
Signed-off-by: Maruthan G <[email protected]>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 25, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

performance.timerify(fn) behave inconsistently for sync/async functions

2 participants