-
Notifications
You must be signed in to change notification settings - Fork 58
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
Host throws exception when initialized multiple times by JS workers #93
Comments
My dependency graph was actually calling the |
That should be fine. Subsequent calls to load the same assembly file will just immediately return the already-loaded assembly object. After looking into this further, I'm not sure my analysis above of the root cause was correct. We actually have a test case that loads .NET from multiple workers in a process, and it works. I'm unable to reproduce the error (except using private APIs that you wouldn't be calling). Can you share:
|
So I have replicated my issue in a public repo (https://github.com/rijulg/node-api-dotnet-issue), unfortunately even the simple example is a bit involved as the bug I encountered was in a project using nestjs so bear with me. I have enapsulated all my project requirements in a devcontainer for running locally, so it should be easy to run locally if you need to. Essentially we see the following in github actions (but not when running locally):
You can see the issue over at this github action report: |
This is very likely nodejs/node#6624, or at least related to it. I happen to have investigated an issue for another project a couple years ago that I traced to Node.js mixing up the drive letter case in the context of a test runner, which led to some modules being loaded multiple times when they shouldn't be. (So I know it's not fully fixed in Node.js.) And there are comments from others specifically mentioning it is a problem with #95 should fix it. |
At least the error changed: https://github.com/rijulg/node-api-dotnet-issue/actions/runs/4697994667/jobs/8329728914
while running the following in second test import { load as loadDLL } from "node-api-dotnet"; Still the error is just on github actions and not locally which is weird. |
The NRE is fixed by #96 I was able to repro and test it better this time. |
Yup, the new fix works Waiting on merge so that I can update my dependncies to the main branch. Thank you so much Jason! |
The
node-api-dotnet
native host throws an exception if itsinitialize()
function is called multiple times in the same process:Normally a JS
require()
will return the same object if called more than once for the same module path. But multiple initializations can happen for either of two reasons:require('node-api-dotnet/net6.0')
andrequire('node-api-dotnet/net7.0')
.The first case is a valid error, since, as the error message says, multiple .NET versions in the same process are not supported.
But the second case should work. The native host can check if the same .NET version is requested and if so the re-initialization can be allowed. Then the managed host should use a separate assembly load context for each worker.
The text was updated successfully, but these errors were encountered: