Skip to content

fix deadlock

Sylvain Fargier requested to merge wip-deadlock into master
  • removed the acquire/release on threadsafe function, there's only one Server object that manages the function lifespan (and it's now similar to AccessPoint implementation)
  • add a timeout and check on server thread in CMW callbacks (CMW thread context)
  • ensured that JS threads are safe by relying on env and napi_get_reference_value(env, wrapper)

the check on env+wrapper is safe for the following reasons:

  • stop is always called from JS context, thus can't run in parallel with JS threads (no need to add mutex to protect one or the other)
  • once threads are released (from stop, using abort option), all queued callbacks will be called with a null env and callback (I checked in node code), thus napi_get_reference_value fails aborting the JS threads methods
  • memory is still freed by the callbacks when needed even when aborted (the small delete at the end of JS thread functions)

There's just one last doubt, it's whereas napi_call_threadsafe_function can be called after threads have been released, but I assumed that server->shutdown() was synchronuous and that we had the guarantee that no other callbacks will be fired when getting out of this function.

Merge request reports