Repository navigation
fix(worker): tear down a worker runtime whose Java bootstrap failed - #2069
adrian-niculescu wants to merge 2 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. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthrough
ChangesRuntime shutdown recovery
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to A Java bootstrap failure after native initialization now allows shutdown to clean up the worker’s runtime. The inspected path supports the change, with no actionable merge-blocking risk established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks the runtime’s trail, Comment |
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.
|
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