Title: Important change of behaviour starting with Node.js v26.4.0 impacting async work in native modules · Issue #1756 · nodejs/node-addon-api · GitHub
Open Graph Title: Important change of behaviour starting with Node.js v26.4.0 impacting async work in native modules · Issue #1756 · nodejs/node-addon-api
X Title: Important change of behaviour starting with Node.js v26.4.0 impacting async work in native modules · Issue #1756 · nodejs/node-addon-api
Description: Starting from Node.js v26.4.0 native modules are expected to call the micro tasks queue and process.nextTick handlers themselves if they do any async work. Node.js exports a RAII guard, CallbackScope, that does automatically at the end o...
Open Graph Description: Starting from Node.js v26.4.0 native modules are expected to call the micro tasks queue and process.nextTick handlers themselves if they do any async work. Node.js exports a RAII guard, CallbackSco...
X Description: Starting from Node.js v26.4.0 native modules are expected to call the micro tasks queue and process.nextTick handlers themselves if they do any async work. Node.js exports a RAII guard, CallbackSco...
Opengraph URL: https://github.com/nodejs/node-addon-api/issues/1756
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Important change of behaviour starting with Node.js v26.4.0 impacting async work in native modules","articleBody":"Starting from Node.js v26.4.0 native modules are expected to call the micro tasks queue and `process.nextTick` handlers themselves if they do any async work.\n\nNode.js exports a RAII guard, `CallbackScope`, that does automatically at the end of the functions that create it.\n\nThe module is supposed to be doing this on the main thread after the async work has been completed.\n\nOr, alternatively, there is the `makeCallback` method which combines a `CallbackScope` with a `Call` method - it is a shorthand for calling into JavaScript _and_ running the micro tasks.\n\nIt appears that this has been specified to work this way since Node.js v9.0.0 but until now Node.js would always process the handlers in all cases. Starting with Node.js v26.4.0, this is no longer the case.\n\nI have first encountered the problem with NAN and I haven't reproduced it with `node-addon-api`, but I see that this fully applies to it too.\n\nNote that Node.js still calls the micro tasks _most of the time_ except in some cases, which makes debugging this problem rather unpleasant.\n\n* The default `OnOK``AsyncWorker` uses `Call` instead of `makeCallback`\n* There is an `AsyncResource` class but this class is not used at all by `AsyncWorker` - it is up to the module to create it\n* This is also true when using the `Promise` helpers - they do not call the micro tasks either\n\nUnlike NAN, `node-addon-api` exports all necessary APIs, however it is currently somewhat misleading and definitely does not make it clear that this is something that is up to the module (especially since until Node.js v26.4.0 it was not).\n\nI think that by default the `AsyncWorker` class should create an `AsyncContext` that must be accessible to derived classes (`protected`) and the `OnOK`/`OnError` methods should use `makeCallback` with this async context. When using a `Promise` - or when overriding `OnOK`/`OnError`, there should be a mention in the documentation that the module must use a `CallbackScope`.\n\nFurther info:\nhttps://github.com/nodejs/nan/issues/1024\nhttps://github.com/nodejs/node/issues/66158","author":{"url":"https://github.com/mmomtchev","@type":"Person","name":"mmomtchev"},"datePublished":"2026-09-26T16:08:02Z","url":"https://github.com/nodejs/node-addon-api/issues/1756"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:6d8c20e9-084e-91cd-1c3b-3305eac23903 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DCA:2C6577:A2EFB3:D965BC:6B063ED9 |
| html-safe-nonce | ae0ad39273f11ee744a2b4250e53e4eadc2d5e85a93ee923c4971f81388c3a4b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RENBOjJDNjU3NzpBMkVGQjM6RDk2NUJDOjZCMDYzRUQ5IiwidmlzaXRvcl9pZCI6IjIyNDk3NDg0ODc1NjA2NDIyNjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ca17f12aa54c0b57d02f9176e402174e089e9fb6a6835526f6f4a38cfc0df6f1 |
| hovercard-subject-tag | issue:5595373733 |
| 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-addon-api/1756/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c5334af865dd935fe95df45865d7376d7aba496d43c3d05fb10336d2bbbda159/nodejs/node-addon-api/issues/1756 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c5334af865dd935fe95df45865d7376d7aba496d43c3d05fb10336d2bbbda159/nodejs/node-addon-api/issues/1756 |
| og:image:alt | Starting from Node.js v26.4.0 native modules are expected to call the micro tasks queue and process.nextTick handlers themselves if they do any async work. Node.js exports a RAII guard, CallbackSco... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mmomtchev |
| hostname | github.com |
| expected-hostname | github.com |
| None | dcf72c457c022486d23c3cbb0dd21aba537a87611ca9ddabd1799cf2eaa9b297 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node-addon-api git https://github.com/nodejs/node-addon-api.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 81384578 |
| octolytics-dimension-repository_nwo | nodejs/node-addon-api |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81384578 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node-addon-api |
| 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 | 0f38f5735226749ec5e08a8649dce4cb2613d9ad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width