deno icon indicating copy to clipboard operation
deno copied to clipboard

valid usage of napi_ref_threadsafe_function can cause 100% cpu usage

Open littledivy opened this issue 2 years ago • 0 comments

Simple example like this causes a hot loop in Deno's implementation. The module continues to function, see below:

// from fsevents ...
CHECK(napi_create_threadsafe_function(env, argv[3], asyncResource, asyncName, 0, 2, NULL, NULL, NULL, fse_dispatch_event, &instance->callback) == napi_ok);
CHECK(napi_ref_threadsafe_function(env, instance->callback) == napi_ok);

image

We need to rethink use of event loop middleware. I think each tsfn should get a waker to the main thread instead.

littledivy avatar Feb 08 '23 04:02 littledivy