"A dynamic link library (DLL) initialization routine failed" when run in Windows under Electron or PKG
- Dominant language
- JavaScript
- Stars
- 102
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
When I run software under Electron or [PKG](https://github.com/vercel/pkg) that runs bcrypto with native bindings on Windows, I get a "DLL Initialization Routine Failed" error. The error looks like this:
```
Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\Matthew Slipper\IdeaProjects\hsd\node_modules\bcrypto\build\Release\bcrypto.node
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1186:18)
at Module.load (internal/modules/cjs/loader.js:984:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1024:19)
at Module.require (pkg/prelude/bootstrap.js:1225:31)
at require (internal/modules/cjs/helpers.js:72:18)
at bindings (C:\snapshot\hsd\node_modules\loady\lib\loady.js:98:17)
at Object. (C:\snapshot\hsd\node_modules\bcrypto\lib\native\binding.js:14:33)
at Module._compile (pkg/prelude/bootstrap.js:1320:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
```
I've already verified that the Node ABI version in use is correct. After attaching WinDBG to the PKG-generated process, I see the following error:
```
ModLoad: 00007ffe`4a130000 00007ffe`4a23e000 \\?\C:\Users\Matthew Slipper\IdeaProjects\hsd\node_modules\bdb\build\Release\leveldown.node
ModLoad: 00007ffe`409d0000 00007ffe`40b1a000 \\?\C:\Users\Matthew Slipper\IdeaProjects\hsd\node_modules\bcrypto\build\Release\bcrypto.node
ModLoad: 00007ffe`8c4b0000 00007ffe`8c4c7000 C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
ModLoad: 00007ff7`12a80000 00007ff7`1499f000 C:\Program Files\nodejs\node.exe
(436c.1a2c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
```
(Note: The exception is not handled, since WinDBG goes into a loop after stepping over the exception.)
The error is the same when I debug Bob in the same way. Error code `c0000005` isn't a missing DLL error, it implies a runtime bug within `bcrypto` itself that is triggering a memory access violation. Any chance you could take a look and see what is going on? Being able to bundle HSD via PKG would dramatically simplify Bob development, and allow people to make standalone HSD binaries in the future.
The issue is not present when HSD is run from my system Nodejs interpreter. The error disappears when I set `process.env.NODE_BACKEND` to `js`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the Windows failure through lib/native/binding.js and the native bcrypto.node loaded via loady/lib/loady.js, using Electron or PKG and WinDBG as described. Compare the native path with NODE_BACKEND=js and inspect the reported access violation. Done means the native binding loads successfully under Electron or PKG on Windows without the DLL initialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript, node.js
- Domain
- backend, cryptography
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100