Skip to content

Commit

Permalink
fixup! src: restrict unloading addons to Worker threads
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Jan 22, 2019
1 parent 0934abd commit d7d409a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/env.cc
Expand Up @@ -276,6 +276,11 @@ Environment::~Environment() {
TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE1(environment), "Environment", this);

// Do not unload addons on the main thread. Some addons need to retain memory
// beyond the Environment's lifetime, and unloading them early would break
// them; with Worker threads, we have the opportunity to be stricter.
// Also, since the main thread usually stops just before the process exits,
// this is far less relevant here.
if (!is_main_thread()) {
// Dereference all addons that were loaded into this environment.
for (binding::DLib& addon : loaded_addons_) {
Expand Down
3 changes: 2 additions & 1 deletion test/addons/worker-addon/binding.cc
Expand Up @@ -49,7 +49,8 @@ void Initialize(Local<Object> exports,
// the Environment instance has been destroyed.
static uv_async_t extra_async;
uv_loop_t* loop = node::GetCurrentEventLoop(context->GetIsolate());
uv_async_init(loop, &extra_async, [](uv_async_t*) {});
int err = uv_async_init(loop, &extra_async, [](uv_async_t*) {});
assert(err == 0);
uv_unref(reinterpret_cast<uv_handle_t*>(&extra_async));
}
}
Expand Down

0 comments on commit d7d409a

Please sign in to comment.