microsoft/node-api-dotnet

NodejsEnvironment Dispose() is blocked by pending tasks

camnewnham opened this issue · 1 comments

In the following snippet, the nodejs environment starts running a task that continues indefinitely:

env.Run(() =>
    {
        JSValue.RunScript(@"
setInterval(() => {
    console.log('Hello from Node.js');
}, 1000);
");
    });

Calling env.Dispose() doesn't kill the environment but instead waits for completion (which never occurs).
Is it possible to forcefully "kill" the node environment?

The NodejsEnvironment.Dispose() method should dispose the environment even if there are pending tasks such as those registered by setImmediate(). So I think this is a bug.

@vmoroz, from debugging this I can see that napi_await_promise() never returns even after the promise is definitely resolved. Is this a bug in that embedding API?