Skip to content

Commit 80f9750

Browse files
fix(worker): tear down a worker runtime whose Java bootstrap failed (#2069)
When Runtime.initWorkerRuntime throws after the native runtime is built (for example internal/ts_helpers.js throws, or the logger does once the runtime is up), the runtime id is never returned, so WorkerWrapper::runtime_ stays null and BackgroundLooper skipped the teardown, leaving the runtime and its isolate allocated for the rest of the process. Shutdown now takes the thread's current runtime when runtime_ is null and tears it down on the existing path, detaching it from Java by its own id, since Java may still hold that runtime and its GC subscription.
1 parent b5226a1 commit 80f9750

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎test-app/runtime/src/main/cpp/WorkerWrapper.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,18 @@ void WorkerWrapper::BackgroundLooper(std::shared_ptr<WorkerWrapper> self) {
706706

707707
isTerminating_ = true;
708708

709+
// A bootstrap that failed in Java after the native runtime was built (an
710+
// exception from internal/ts_helpers.js, or from the logger once the
711+
// runtime is up) never handed it back: initWorkerRuntime threw before
712+
// returning its id. It is still this thread's current runtime, so it is
713+
// torn down below like any other, and detached from Java by its own id.
714+
if (runtime_ == nullptr) {
715+
runtime_ = Runtime::GetCurrentRuntime();
716+
if (runtime_ != nullptr) {
717+
runtimeId = runtime_->GetId();
718+
}
719+
}
720+
709721
// Terminate any workers this worker created (nested workers). Their
710722
// Worker object persistents live in this isolate, so they must be
711723
// released before the isolate is disposed below. Each child cascades to

0 commit comments

Comments
 (0)