Skip to content

ffi: do not abort when a Worker stops in a callback - #66389

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:ffi-stopping-worker-in-callback
Open

trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:ffi-stopping-worker-in-callback

Conversation

@trivikr

@trivikr trivikr commented Sep 29, 2026

Copy link
Copy Markdown
Member

Fixes: #66388

Stopping a Worker while it is running an FFI callback aborted the whole process with "Callbacks cannot throw an exception". This happened on worker.terminate(), on process.exit() inside the callback, and when the main thread exited while the Worker was in a callback, since exit terminates all Workers.

All three stop the Worker by terminating execution, and InvokeCallback treated the termination as a thrown exception. Check HasTerminated() first and return a zeroed result so the native caller can unwind. Callbacks that throw still abort.


Assisted-by: claude:opus-5.5

Stopping a Worker while it is running an FFI callback aborted the whole
process with "Callbacks cannot throw an exception". This happened on
worker.terminate(), on process.exit() inside the callback, and when the
main thread exited while the Worker was in a callback, since exit
terminates all Workers.

All three stop the Worker by terminating execution, and InvokeCallback
treated the termination as a thrown exception. Check HasTerminated()
first and return a zeroed result so the native caller can unwind.
Callbacks that throw still abort.

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 Sep 29, 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 Sep 29, 2026
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.36%. Comparing base (296584b) to head (41e4125).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
src/node_ffi.cc 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66389      +/-   ##
==========================================
- Coverage   90.36%   90.36%   -0.01%     
==========================================
  Files         792      792              
  Lines      275490   275569      +79     
  Branches    52796    52836      +40     
==========================================
+ Hits       248954   249016      +62     
- Misses      16936    16957      +21     
+ Partials     9600     9596       -4     
Files with missing lines Coverage Δ
src/node_ffi.cc 72.45% <83.33%> (+0.04%) ⬆️

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

Comment thread src/node_ffi.cc
@trivikr
trivikr requested a review from daeyeon September 30, 2026 04:25
@daeyeon daeyeon added commit-queue-squash PRs the Commit Queue should land as one squashed commit. author ready PRs with CI started, the required approvals, and no outstanding review comments. and removed commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Sep 30, 2026
@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 Sep 30, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@daeyeon daeyeon added the commit-queue PRs queued for automated landing through the Commit Queue. label Sep 30, 2026

@mcollina mcollina 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

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++. commit-queue PRs queued for automated landing through the Commit Queue. 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: stopping a Worker while it is in a callback aborts the process

5 participants