Visitar URL original
fix(worker): keep a worker isolate alive while a __runOnMainThread callback locks it by adrian-niculescu · Pull Request #2068 · NativeScript/android · GitHub
Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(worker): report a worker's __runOnMainThread exception without it…
…s isolate handle

The exception a worker's callback threw kept a handle into the worker isolate after RunMainThreadEntry let go of it, so the isolate could be disposed before the event loop reported it, and the report resolved the handle against the main thread's isolate. For a worker's callback the exception now drops the handle while the isolate is still held, and only its message and stack reach Java.
  • Loading branch information
adrian-niculescu committed Oct 6, 2026
commit a340e10143105ed90a4a19afbd4ea202f829c513
9 changes: 8 additions & 1 deletion test-app/runtime/src/main/cpp/CallbackHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,15 @@ void CallbackHandlers::RunMainThreadEntry(uint64_t key) {

if (tc.HasCaught() &&
!NativeScriptException::ContainUncaughtCallbackException(isolate, tc)) {
NativeScriptException ex(tc);
if (!runtime->IsMainThread()) {
// Reported only after this function lets go of the isolate, which
// its worker may dispose by then, and from the main thread, which
// never enters it: only the message and stack can travel.
ex.ReleaseJsHandle();
}
// surfaces via the event loop's guard as a pending Java exception
throw NativeScriptException(tc);
throw ex;
}
}

Expand Down
Loading