Title: ffi: stopping a Worker while it is in a callback aborts the process · Issue #66388 · nodejs/node · GitHub
Open Graph Title: ffi: stopping a Worker while it is in a callback aborts the process · Issue #66388 · nodejs/node
X Title: ffi: stopping a Worker while it is in a callback aborts the process · Issue #66388 · nodejs/node
Description: Version main Platform macOS 26.7.0 Subsystem ffi What steps will reproduce the bug? import { Worker } from 'node:worker_threads'; // qsort() from the process image calls the JS comparator through node:ffi. const workerSource = ` const { ...
Open Graph Description: Version main Platform macOS 26.7.0 Subsystem ffi What steps will reproduce the bug? import { Worker } from 'node:worker_threads'; // qsort() from the process image calls the JS comparator through n...
X Description: Version main Platform macOS 26.7.0 Subsystem ffi What steps will reproduce the bug? import { Worker } from 'node:worker_threads'; // qsort() from the process image calls the JS comparator t...
Opengraph URL: https://github.com/nodejs/node/issues/66388
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ffi: stopping a Worker while it is in a callback aborts the process","articleBody":"### Version\n\nmain\n\n### Platform\n\n```text\nmacOS 26.7.0\n```\n\n### Subsystem\n\nffi\n\n### What steps will reproduce the bug?\n\n```js\nimport { Worker } from 'node:worker_threads';\n\n// qsort() from the process image calls the JS comparator through node:ffi.\nconst workerSource = `\nconst { parentPort, workerData } = require('node:worker_threads');\nconst ffi = require('node:ffi');\nconst { lib, functions } = ffi.dlopen(null, {\n qsort: { arguments: ['pointer', 'u64', 'u64', 'pointer'], return: 'void' },\n});\nconst compare = lib.registerCallback(\n { arguments: ['pointer', 'pointer'], return: 'i32' },\n () => {\n if (workerData === 'exit') process.exit(0);\n parentPort.postMessage('in callback');\n for (;;);\n },\n);\nconst items = new Int32Array([2, 1]);\nfunctions.qsort(ffi.getRawPointer(items), 2n, 4n, compare);\n`;\n\nconst mode = process.argv[2];\nconst worker = new Worker(workerSource, { eval: true, workerData: mode });\nworker.on('message', () => {\n if (mode === 'shutdown') process.exit(0);\n worker.terminate();\n});\nworker.on('exit', (code) => console.log(`worker exited with code ${code}`));\n```\n\n```console\n$ node --experimental-ffi repro.mjs shutdown # main thread calls process.exit(0) while the Worker is in the callback\n$ node --experimental-ffi repro.mjs terminate # worker.terminate() while the Worker is in the callback\n$ node --experimental-ffi repro.mjs exit # process.exit() inside the callback\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nOnly the Worker stops:\n\n```console\n # shutdown: exit code 0\nworker exited with code 1 # terminate\nworker exited with code 0 # exit\n```\n\nThe docs say that `process.exit()` in a Worker \"stops the current thread rather than the current process\", and that `worker.terminate()` stops \"JavaScript execution in the worker thread\". Neither of these is an exception thrown by the callback.\n\n### What do you see instead?\n\nAll three modes abort the whole process with exit code 134:\n\n```console\nCallbacks cannot throw an exception\n----- Native stack trace -----\n\n 1: 0x102c5f1b8 node::(anonymous namespace)::DefaultAbortHandler(char const*, char const*) \n 2: 0x102cd8cfc node::ffi::DynamicLibrary::InvokeCallback(ffi_cif*, void*, void**, void*) (.cold.5) \n 3: 0x1008e5bc8 node::ffi::DynamicLibrary::InvokeCallback(ffi_cif*, void*, void**, void*) \n 4: 0x101f5e338 ffi_closure_SYSV_inner\n...\n```\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/trivikr","@type":"Person","name":"trivikr"},"datePublished":"2026-09-29T05:26:49Z","url":"https://github.com/nodejs/node/issues/66388"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:36f8baa5-b7ed-fe43-db60-0ac5b59782c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1EA:2973C7:5A6598:754512:6AED28F1 |
| html-safe-nonce | 4e6e3398c69a407526f6aa7c6bae6195c7c62dc6ad5fb5dbe9812b448fe7795e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUVBOjI5NzNDNzo1QTY1OTg6NzU0NTEyOjZBRUQyOEYxIiwidmlzaXRvcl9pZCI6IjE2NDMwMjkyODY5MjgzMjg5NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6eb74d9485a697027bcf8917bfbee174dbbb0d38f0e5249dc428f62aee6654fc |
| hovercard-subject-tag | issue:5625602640 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/66388/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af78c4240e892ce5285e6ee2eb19b4e8ebefbec4b5cd5bfca07db9e49ee5154d/nodejs/node/issues/66388 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af78c4240e892ce5285e6ee2eb19b4e8ebefbec4b5cd5bfca07db9e49ee5154d/nodejs/node/issues/66388 |
| og:image:alt | Version main Platform macOS 26.7.0 Subsystem ffi What steps will reproduce the bug? import { Worker } from 'node:worker_threads'; // qsort() from the process image calls the JS comparator through n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trivikr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d95365dda0576efe9b71f45807595e396bd0ca9286fba5367a05048e6ddf8f2 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 98b41fa4b5635ceb45a4c54320fced73817ff290 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width