Skip to content

Commit d7d409a

Browse files
committed
fixup! src: restrict unloading addons to Worker threads
1 parent 0934abd commit d7d409a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/env.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ Environment::~Environment() {
276276
TRACE_EVENT_NESTABLE_ASYNC_END0(
277277
TRACING_CATEGORY_NODE1(environment), "Environment", this);
278278

279+
// Do not unload addons on the main thread. Some addons need to retain memory
280+
// beyond the Environment's lifetime, and unloading them early would break
281+
// them; with Worker threads, we have the opportunity to be stricter.
282+
// Also, since the main thread usually stops just before the process exits,
283+
// this is far less relevant here.
279284
if (!is_main_thread()) {
280285
// Dereference all addons that were loaded into this environment.
281286
for (binding::DLib& addon : loaded_addons_) {

test/addons/worker-addon/binding.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void Initialize(Local<Object> exports,
4949
// the Environment instance has been destroyed.
5050
static uv_async_t extra_async;
5151
uv_loop_t* loop = node::GetCurrentEventLoop(context->GetIsolate());
52-
uv_async_init(loop, &extra_async, [](uv_async_t*) {});
52+
int err = uv_async_init(loop, &extra_async, [](uv_async_t*) {});
53+
assert(err == 0);
5354
uv_unref(reinterpret_cast<uv_handle_t*>(&extra_async));
5455
}
5556
}

0 commit comments

Comments
 (0)