Repository navigation
fix(worker): tear down a worker runtime whose Java bootstrap failed - #2069
edusperoni merged 3 commits into
Conversation
When initWorkerRuntime built the native runtime and then failed in Java, for example because internal/ts_helpers.js threw, it threw before returning the runtime id, so the worker never took ownership and the native runtime and its isolate were never disposed. Worker shutdown now takes that runtime from the thread's current one and tears it down like any other.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
The bootstrap can also fail after the Java runtime finished initializing, when the logger throws on its last line, and the Java side then still holds the runtime and its GC subscription. Detaching with the id the call never returned left both behind, so a later GC notification could reach the deleted native runtime.
|
@coderabbitai review |
✅ Action performedReview finished.
|
edusperoni
left a comment
There was a problem hiding this comment.
Reviewed and verified. Reproduced on device with internal/ts_helpers.js patched to throw on worker threads: three failed bootstraps each recovered the runtime, tore it down (current runtime null afterwards), reported exactly one error to the parent and fired nsworkerended, with no crash. Full device suite passes on main + #2067 + #2070 + #2069 (1545 specs, 0 failures, 3 runs).
A worker whose bootstrap fails after its native runtime is up, for example because
internal/ts_helpers.jsthrows, reports the error to its parent but leaves the native runtime and its isolate allocated for the rest of the process.Runtime.initWorkerRuntimecreates the native runtime inruntime.init()and then runsts_helpers.js. When that throws, the Java side rolls back its own caches and rethrows, so the call never returns the runtime id,WorkerWrapper::runtime_stays null, andBackgroundLooperskips the teardown that disposes the isolate. The native runtime is still the thread's current runtime (PrepareV8Runtimesets it last, andUnwindFailedInitclears it when native init itself fails), so shutdown now takes it from there whenruntime_is null and tears it down on the existing path, detaching it from Java by its own id. That id matters when the failure comes after the Java runtime finished initializing, for example a logger that throws on its last line: Java still holds that runtime and its GC subscription, and detaching with the-1the call never replaced would leave both pointing at the deleted native runtime.With
ts_helpers.jspatched to throw in workers, a failed worker onmainleaves its runtime current after shutdown, and with this change the runtime is gone and the error still reaches the parent once. That needs a patched asset, so there is no spec for it. The full device suite passes.Summary by CodeRabbit