Fix mtx_do_lock on exit or reload context #170
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We made an effort to try using AddCleanupHook to stop the watcher on all NSFW instances when exiting from a worker or electron context, but in the end we couldn’t make it work correctly, so we had to stop using them.
The reason is that using CleanupHooks introduces a problem: if you create and free a NSFW object when you close o reload a context or worker the CleanupHook will be triggered on an already freed object, so you will get a crash. We have tried to remove the CleanupHook before that, but you will get a crash if you try to remove it in the destructor. You cannot create or remove a CleanupHook anywhere you want, you can only do it when you have access to Napi::env directly in the call, and you cannot store it to use it later in the destructor.