Skip to content

feat(node): implement async hooks for nextTick TickObject tracking - #30578

Merged
bartlomieju merged 5 commits into
mainfrom
DENB-29802-8
Sep 3, 2025
Merged

bartlomieju merged 5 commits into
mainfrom
DENB-29802-8

Conversation

@gitstart-app

@gitstart-app gitstart-app Bot commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

This PR was created by GitStart to address the requirements from this ticket: DENB-29802.


Summary

Adds Async Hooks support for process.nextTick() to enable TickObject lifecycle tracking, unblocking the Node.js compatibility test test-stream-writable-samecb-singletick.js.


Changes

  • Async hook emissions: implement emitInit(), emitBefore(), emitAfter(), emitDestroy().
  • Async IDs & context: implement nextAsyncId() and executionAsyncId() with an execution context stack.
  • TickObject integration: wire async hooks into _next_tick.ts.
  • Safety: mirror Node.js protection patterns (try/catch + finally) to prevent stack corruption.
  • Hook API: update createHook() to use the internal AsyncHook implementation.
  • Cleanup: remove deprecated helpers and FIXME comments.

Fixes

  • Prevents stack overflows when async hook callbacks throw.
  • Guards against execution context corruption.
  • Avoids memory leaks from unbounded context stack growth.

Testing

  • test-stream-writable-samecb-singletick.js passes
  • Format, lint, and type checks pass
  • Basic Async Hooks behavior verified

gitstart-app[bot] and others added 5 commits September 1, 2025 03:35
  - Add functional emitInit, emitBefore, emitAfter, emitDestroy implementations
  - Implement async ID generation with executionAsyncIdStack tracking
  - Add TickObject async hooks integration in _next_tick.ts
  - Include Node.js-style stack corruption protection (try/catch + finally)
  - Update createHook to use internal AsyncHook implementation
  - Remove FIXME comments and deprecated helper functions

  Fixes test-stream-writable-samecb-singletick.js by enabling proper
  TickObject lifecycle tracking through async hooks.

@bartlomieju bartlomieju 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.

This looks good, I want to do some more testing before landing, but the test appears to be passing now πŸ‘

@bartlomieju
bartlomieju merged commit e85fc18 into main Sep 3, 2025
@bartlomieju
bartlomieju deleted the DENB-29802-8 branch September 3, 2025 08:44
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.

1 participant