Skip to content

ffi: drain task queues after event loop callbacks - #66918

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-event-loop-invoked-callbacks
Open

trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-event-loop-invoked-callbacks

Conversation

@trivikr

@trivikr trivikr commented Oct 22, 2026

Copy link
Copy Markdown
Member

Fixes: #66917

When native code invokes a registered callback from the event loop, no callback scope is active. A nextTick or microtask queued by the callback only ran when an unrelated Node.js callback fired, or at beforeExit.

Open an InternalCallbackScope in InvokeCallback when no scope is active, so the queues are drained when the callback returns. Callbacks invoked synchronously during a call into native code already run inside the caller's scope and are left unchanged.


Assisted-by: claude:opus-5.5

When native code invokes a registered callback from the event loop,
no callback scope is active. A nextTick or microtask queued by the
callback only ran when an unrelated Node.js callback fired, or at
beforeExit.

Open an InternalCallbackScope in InvokeCallback when no scope is
active, so the queues are drained when the callback returns.
Callbacks invoked synchronously during a call into native code
already run inside the caller's scope and are left unchanged.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 22, 2026
@trivikr trivikr added ffi Issues and PRs related to experimental Foreign Function Interface support. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 22, 2026
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.58%. Comparing base (e0619bb) to head (d9cf6ad).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66918   +/-   ##
=======================================
  Coverage   90.58%   90.58%           
=======================================
  Files         797      797           
  Lines      278494   278499    +5     
  Branches    53541    53539    -2     
=======================================
+ Hits       252270   252288   +18     
- Misses      16547    16558   +11     
+ Partials     9677     9653   -24     
Files with missing lines Coverage Δ
src/node_ffi.cc 72.77% <100.00%> (+0.15%) ⬆️

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

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 22, 2026
@nodejs-github-bot

This comment was marked as outdated.

@trivikr trivikr added author ready PRs with CI started, the required approvals, and no outstanding review comments. resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Oct 22, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Oct 22, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ffi: nextTick and microtasks queued in event-loop-invoked callbacks are not drained

4 participants