Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node hard crash when importing napi module #57233

Closed
t3chguy opened this issue Feb 28, 2025 · 6 comments
Closed

Node hard crash when importing napi module #57233

t3chguy opened this issue Feb 28, 2025 · 6 comments
Labels
invalid Issues and PRs that are invalid.

Comments

@t3chguy
Copy link

t3chguy commented Feb 28, 2025

Version

22.14.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

but we also had reports of this happening under Arch Linux https://gitlab.archlinux.org/archlinux/packaging/packages/element.io/-/issues/14

Subsystem

NAPI

What steps will reproduce the bug?

Building https://github.com/atom/node-keytar napi using lts-jod makes it incompatible with many other versions of Node, such as the one in Electron 32 (20.18). Building the same package in the same manner using Node 22.13.1 works when running in 20.18.

The keytar.node file built in 22.14.0:

  • Works fine under Node 18.15.0
  • Explodes under Node 20.18.3 (Node & Electron)
  • Explodes under Node 22.13.1
  • Works fine under Node 22.14.0

How often does it reproduce? Is there a required condition?

Crashes every time on affected versions.

Building the same package in the same manner using Node 22.13.1 works when running in 20.18.

What is the expected behavior? Why is that the expected behavior?

I expect the NAPI module to work on all versions of Node with support for that NAPI version, and definitely not to break on a minor version bump then start working again after a major.

I would also expect this to be caught by the try-catch the require was within.

What do you see instead?

Image


#0  0x000063b014b8fa2f in napi_module_register_by_symbol(v8::Local, v8::Local, v8::Local, napi_value__* (*)(napi_env__*, napi_value__*), int) ()
#1  0x000063b014ba3c68 in std::__Cr::__function::__func const&)::$_0, std::__Cr::allocator const&)::$_0>, bool (node::binding::DLib*)>::operator()(node::binding::DLib*&&) [clone .7c615a08d3fa147d897e7ccdbe9ce979] ()
#2  0x000063b014b6d293 in node::Environment::TryLoadAddon(char const*, int, std::__Cr::function const&) ()
#3  0x000063b014ba1d42 in node::binding::DLOpen(v8::FunctionCallbackInfo const&) ()
#4  0x000063b00bfbd85e in Builtins_CallApiCallbackGeneric ()
#5  0x00007ffe33899a88 in ?? ()
#6  0x00007ffe33899ac0 in ?? ()
#7  0x0000000000000002 in ?? ()
#8  0x00007ffe33899a50 in ?? ()
#9  0x0000000000000038 in ?? ()
#10 0x00007ffe33899b58 in ?? ()
#11 0x000063b00bfbba0b in Builtins_InterpreterEntryTrampoline ()
#12 0x000008f3003ced61 in ?? ()
#13 0x000025bc00108000 in ?? ()
#14 0x000008f300100099 in ?? ()
#15 0x000008f300000011 in ?? ()
#16 0x000008f300199ad5 in ?? ()
#17 0x000008f300000011 in ?? ()
#18 0x000008f3003ced61 in ?? ()
#19 0x000008f3006217d1 in ?? ()
#20 0x000008f300622361 in ?? ()
#21 0x000008f300000011 in ?? ()
#22 0x000008f300199ad5 in ?? ()
#23 0x000008f3001008ed in ?? ()
#24 0x000008f300000011 in ?? ()
#25 0x000008f300000011 in ?? ()
#26 0x000008f300000011 in ?? ()
#27 0x000008f300000011 in ?? ()
#28 0x000008f300622641 in ?? ()
#29 0x000008f300622361 in ?? ()
#30 0x000008f3006223cd in ?? ()
#31 0x000008f3006223cd in ?? ()
#32 0x000008f300000011 in ?? ()
#33 0x00000000000000a0 in ?? ()
#34 0x000012ca00161191 in ?? ()
#35 0x0000000000000003 in ?? ()
#36 0x000008f30074a84d in ?? ()
#37 0x000008f30074b819 in ?? ()
#38 0x00007ffe33899bf0 in ?? ()
#39 0x000063b00bfbba0b in Builtins_InterpreterEntryTrampoline ()
#40 0x000008f3003ced61 in ?? ()
#41 0x000008f3006217d1 in ?? ()
#42 0x000008f300622361 in ?? ()
#43 0x000008f3004c0f05 in ?? ()
#44 0x000008f300622361 in ?? ()
#45 0x000008f300000011 in ?? ()
#46 0x000008f3003ced61 in ?? ()
#47 0x000008f30074a84d in ?? ()
#48 0x000008f300000011 in ?? ()
#49 0x000008f300000011 in ?? ()
#50 0x000008f300000011 in ?? ()
#51 0x000008f300000011 in ?? ()
#52 0x00000000000000f2 in ?? ()
#53 0x000012ca001612ed in ?? ()
#54 0x0000000000000003 in ?? ()
#55 0x000008f3003c5ea5 in ?? ()
#56 0x000008f30050af55 in ?? ()
#57 0x00007ffe33899ca0 in ?? ()
#58 0x000063b00bfbba0b in Builtins_InterpreterEntryTrampoline ()
#59 0x000008f3004c0cb1 in ?? ()
#60 0x000008f3006217d1 in ?? ()
#61 0x000008f300622361 in ?? ()
#62 0x000008f300000011 in ?? ()
#63 0x000008f3003c5ea5 in ?? ()
#64 0x000008f3001008ed in ?? ()
#65 0x000008f300622361 in ?? ()
#66 0x000008f3007eb2ad in ?? ()
#67 0x000008f300622311 in ?? ()
#68 0x000008f3006222d5 in ?? ()
#69 0x000008f3006222a5 in ?? ()
#70 0x000008f300621769 in ?? ()
#71 0x000008f300622035 in ?? ()
#72 0x000008f300622035 in ?? ()
#73 0x000008f300000011 in ?? ()
#74 0x000000000000019a in ?? ()
#75 0x000012ca00161191 in ?? ()
#76 0x0000000000000003 in ?? ()
#77 0x000008f3007c06f1 in ?? ()
#78 0x000008f3007c29bd in ?? ()
#79 0x00007ffe33899d30 in ?? ()
#80 0x000063b06c046b7c in ?? ()
#81 0x000008f3004c0cb1 in ?? ()
#82 0x000008f3006217d1 in ?? ()
#83 0x000008f300621769 in ?? ()
#84 0x000008f3004c0f05 in ?? ()
#85 0x000008f30062192d in ?? ()
#86 0x000008f300406511 in ?? ()
#87 0x000008f3004c0cb1 in ?? ()
#88 0x000008f3007c06f1 in ?? ()
#89 0x000008f300000011 in ?? ()
#90 0x000008f300622011 in ?? ()
#91 0x000008f300c7d97d in ?? ()
#92 0x000008f3003c50f9 in ?? ()
#93 0x000012ca000508e5 in ?? ()
#94 0x0000000000000002 in ?? ()
#95 0x000008f3003c5e05 in ?? ()
#96 0x000008f30050af55 in ?? ()
#97 0x00007ffe33899e20 in ?? ()
#98 0x000063b06c0459f0 in ?? ()
#99 0x000008f3006217d1 in ?? ()
#100 0x000008f300621769 in ?? ()
#101 0x000008f300000011 in ?? ()
#102 0x000008f300000011 in ?? ()
#103 0x000008f300000011 in ?? ()
#104 0x000008f3003c5e05 in ?? ()
#105 0x000008f30050af55 in ?? ()
#106 0x000008f300000739 in ?? ()
#107 0x000008f3003c51b9 in ?? ()
#108 0x000008f30051fbb9 in ?? ()
#109 0x000008f300000011 in ?? ()
#110 0x000008f300000011 in ?? ()
#111 0x000008f300000011 in ?? ()
#112 0x000008f300000011 in ?? ()
#113 0x000008f300000011 in ?? ()
#114 0x000008f300000011 in ?? ()
#115 0x000008f300000011 in ?? ()
#116 0x000008f300000071 in ?? ()
#117 0x000008f3006217d1 in ?? ()
#118 0x000008f300000011 in ?? ()
#119 0x000008f300621769 in ?? ()
#120 0x000008f30061ff51 in ?? ()
#121 0x000008f300c7cbc9 in ?? ()
#122 0x000008f3003c50d9 in ?? ()
#123 0x000012ca000fc039 in ?? ()
#124 0x0000000000000004 in ?? ()
#125 0x000008f3003c5d75 in ?? ()
#126 0x000008f30050af55 in ?? ()
#127 0x00007ffe33899e80 in ?? ()
#128 0x000063b06bff64c3 in ?? ()
#129 0x000008f300000011 in ?? ()
#130 0x000008f300fed23d in ?? ()
#131 0x000008f30061d25d in ?? ()
#132 0x000008f300000055 in ?? ()
#133 0x0000000000000000 in ?? ()
quit
#0  0x00006430153ada2f in napi_module_register_by_symbol(v8::Local, v8::Local, v8::Local, napi_value__* (*)(napi_env__*, napi_value__*), int) ()
#1  0x00006430153c1c68 in std::__Cr::__function::__func const&)::$_0, std::__Cr::allocator const&)::$_0>, bool (node::binding::DLib*)>::operator()(node::binding::DLib*&&) [clone .7c615a08d3fa147d897e7ccdbe9ce979] ()
#2  0x000064301538b293 in node::Environment::TryLoadAddon(char const*, int, std::__Cr::function const&) ()
#3  0x00006430153bfd42 in node::binding::DLOpen(v8::FunctionCallbackInfo const&) ()
#4  0x000064300c7db85e in Builtins_CallApiCallbackGeneric ()
#5  0x00007ffff0f87088 in ?? ()
#6  0x00007ffff0f870c0 in ?? ()
#7  0x0000000000000002 in ?? ()
#8  0x00007ffff0f87050 in ?? ()
#9  0x0000000000000038 in ?? ()
#10 0x00007ffff0f87158 in ?? ()
#11 0x000064300c7d9a0b in Builtins_InterpreterEntryTrampoline ()
#12 0x000020a5003ccb85 in ?? ()
#13 0x000033dc00108000 in ?? ()
#14 0x000020a500100099 in ?? ()
#15 0x000020a500000011 in ?? ()
#16 0x000020a500397f1d in ?? ()
#17 0x000020a500000011 in ?? ()
#18 0x000020a5003ccb85 in ?? ()
#19 0x000020a5005a1925 in ?? ()
#20 0x000020a5005a24b5 in ?? ()
#21 0x000020a500000011 in ?? ()
#22 0x000020a500397f1d in ?? ()
#23 0x000020a5001008ed in ?? ()
#24 0x000020a500000011 in ?? ()
#25 0x000020a500000011 in ?? ()
#26 0x000020a500000011 in ?? ()
#27 0x000020a500000011 in ?? ()
#28 0x000020a5005a2795 in ?? ()
#29 0x000020a5005a24b5 in ?? ()
#30 0x000020a5005a2521 in ?? ()
#31 0x000020a5005a2521 in ?? ()
#32 0x000020a500000011 in ?? ()
#33 0x00000000000000a0 in ?? ()
#34 0x00001b480009b3b1 in ?? ()
#35 0x0000000000000003 in ?? ()
#36 0x000020a500749d2d in ?? ()
#37 0x000020a50074a0fd in ?? ()
#38 0x00007ffff0f871f0 in ?? ()
#39 0x000064300c7d9a0b in Builtins_InterpreterEntryTrampoline ()
#40 0x000020a5003ccb85 in ?? ()
#41 0x000020a5005a1925 in ?? ()
#42 0x000020a5005a24b5 in ?? ()
#43 0x000020a5004c0e9d in ?? ()
#44 0x000020a5005a24b5 in ?? ()
#45 0x000020a500000011 in ?? ()
#46 0x000020a5003ccb85 in ?? ()
#47 0x000020a500749d2d in ?? ()
#48 0x000020a500000011 in ?? ()
#49 0x000020a500000011 in ?? ()
#50 0x000020a500000011 in ?? ()
#51 0x000020a500000011 in ?? ()
#52 0x00000000000000f2 in ?? ()
#53 0x00001b480009b50d in ?? ()
#54 0x0000000000000003 in ?? ()
#55 0x000020a5003c5e7d in ?? ()
#56 0x000020a5004c1ee1 in ?? ()
#57 0x00007ffff0f872a0 in ?? ()
#58 0x000064300c7d9a0b in Builtins_InterpreterEntryTrampoline ()
#59 0x000020a5004c0c85 in ?? ()
#60 0x000020a5005a1925 in ?? ()
#61 0x000020a5005a24b5 in ?? ()
#62 0x000020a500000011 in ?? ()
#63 0x000020a5003c5e7d in ?? ()
#64 0x000020a5001008ed in ?? ()
#65 0x000020a5005a24b5 in ?? ()
#66 0x000020a5007594ed in ?? ()
#67 0x000020a5005a2465 in ?? ()
#68 0x000020a5005a2429 in ?? ()
#69 0x000020a5005a23f9 in ?? ()
#70 0x000020a5005a18bd in ?? ()
#71 0x000020a5005a2189 in ?? ()
#72 0x000020a5005a2189 in ?? ()
#73 0x000020a500000011 in ?? ()
#74 0x000000000000019a in ?? ()
#75 0x00001b480009b3b1 in ?? ()
#76 0x0000000000000003 in ?? ()
#77 0x000020a500749239 in ?? ()
#78 0x000020a50074ced9 in ?? ()
#79 0x00007ffff0f87330 in ?? ()
#80 0x000064306c886b7c in ?? ()
#81 0x000020a5004c0c85 in ?? ()
#82 0x000020a5005a1925 in ?? ()
#83 0x000020a5005a18bd in ?? ()
#84 0x000020a5004c0e9d in ?? ()
#85 0x000020a5005a1a81 in ?? ()
#86 0x000020a5004069f1 in ?? ()
#87 0x000020a5004c0c85 in ?? ()
#88 0x000020a500749239 in ?? ()
#89 0x000020a500000011 in ?? ()
#90 0x000020a5005a2165 in ?? ()
#91 0x000020a500cd45a5 in ?? ()
#92 0x000020a5003c50d1 in ?? ()
#93 0x00001b48000508e5 in ?? ()
#94 0x0000000000000002 in ?? ()
#95 0x000020a5003c5ddd in ?? ()
#96 0x000020a5004c1ee1 in ?? ()
#97 0x00007ffff0f87420 in ?? ()
#98 0x000064306c8859f0 in ?? ()
#99 0x000020a5005a1925 in ?? ()
#100 0x000020a5005a18bd in ?? ()
#101 0x000020a500000011 in ?? ()
#102 0x000020a500000011 in ?? ()
#103 0x000020a500000011 in ?? ()
#104 0x000020a5003c5ddd in ?? ()
#105 0x000020a5004c1ee1 in ?? ()
#106 0x000020a500000739 in ?? ()
#107 0x000020a5003c5191 in ?? ()
#108 0x000020a50050e381 in ?? ()
#109 0x000020a500000011 in ?? ()
#110 0x000020a500000011 in ?? ()
#111 0x000020a500000011 in ?? ()
#112 0x000020a500000011 in ?? ()
#113 0x000020a500000011 in ?? ()
#114 0x000020a500000011 in ?? ()
#115 0x000020a500000011 in ?? ()
#116 0x000020a500000071 in ?? ()
#117 0x000020a5005a1925 in ?? ()
#118 0x000020a500000011 in ?? ()
#119 0x000020a5005a18bd in ?? ()
#120 0x000020a5005a00a5 in ?? ()
#121 0x000020a500cd37f1 in ?? ()
#122 0x000020a5003c50b1 in ?? ()
#123 0x00001b48000fc039 in ?? ()
#124 0x0000000000000004 in ?? ()
#125 0x000020a5003c5d4d in ?? ()
#126 0x000020a5004c1ee1 in ?? ()
#127 0x00007ffff0f87480 in ?? ()
#128 0x000064306c89c943 in ?? ()
#129 0x000020a500000011 in ?? ()
#130 0x000020a5010aa5b5 in ?? ()
#131 0x000020a50059d3b1 in ?? ()
#132 0x000020a500000055 in ?? ()
#133 0x0000000000000000 in ?? ()
quit

Additional information

keytar.zip
94 is built using 22.14.0 and is problematic
93 is built using 22.13.1 and works fine

I don't have the tooling to figure out the differences between them

Downstream issue element-hq/element-desktop#2161

@t3chguy
Copy link
Author

t3chguy commented Feb 28, 2025

Looks like the issue is due to inspiredware/napi-build-utils#6 & prebuild/prebuild-install#203 but should one expect NAPI 10 to ship mid-LTS and cause breakages such as this? Its also missing from documentation https://nodejs.org/api/n-api.html#node-api-version-matrix

@bnoordhuis
Copy link
Member

That's a bug in that tool (bad version check), not in napi.

The documentation omission seems like an oversight though. @nodejs/documentation - napi 10 is not mentioned in the docs/api/n-api.md version matrix in any release line. Are there plans to back-port it to v20.x or v18.x?

@bnoordhuis bnoordhuis added the doc Issues and PRs related to the documentations. label Feb 28, 2025
@t3chguy
Copy link
Author

t3chguy commented Feb 28, 2025

I'd agree if a require in a try catch didn't segfault my app and thousands of users. Either a try catch should work or there should be no napi changes within an lts branch surely. I don't see how such a failure mode is acceptable even if technically the crash didn't happen in your code.

@bnoordhuis
Copy link
Member

It's not really up for the discussion. The tool you used did something wrong and miscompiled your project, end of story.

@t3chguy
Copy link
Author

t3chguy commented Mar 3, 2025

You're right. Its not up for discussion. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch around any dependency require should work. node-keytar is no different. Node should do better than segfault if the house of cards falls apart. The tool I used didn't compile Node for me. Node normally handles require errors just fine

> require("./Whatever")
Uncaught Error: Cannot find module './Whatever'
Require stack:
- <repl>
    at Function._resolveFilename (node:internal/modules/cjs/loader:1394:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1050:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1055:22)
    at Function._load (node:internal/modules/cjs/loader:1204:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
    at Module.require (node:internal/modules/cjs/loader:1480:12)
    at require (node:internal/modules/helpers:135:16) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}

So in a try-catch would hand me this error on a platter.

Yet when dealing with N-API when things go wrong your process is quit and you have no recourse. This makes Node unusable as the outer process for any app which must achieve stability if N-API is in play, and you must have a watchdog/orchestrator wrapping the app to ensure such a case is handled.

@bnoordhuis
Copy link
Member

I'm going to close this because, with all due respect, I don't think you understand what you're talking about. I'll open a new issue for the tracking the documentation update.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2025
@github-project-automation github-project-automation bot moved this from Need Triage to Done in Node-API Team Project Mar 3, 2025
@bnoordhuis bnoordhuis added invalid Issues and PRs that are invalid. and removed doc Issues and PRs related to the documentations. node-api Issues and PRs related to the Node-API. labels Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid.
Projects
Development

No branches or pull requests

3 participants