René's URL Explorer Experiment


Title: fix(worker): drop callbacks from closing workers by edusperoni · Pull Request #2108 · NativeScript/android · GitHub

Open Graph Title: fix(worker): drop callbacks from closing workers by edusperoni · Pull Request #2108 · NativeScript/android

X Title: fix(worker): drop callbacks from closing workers by edusperoni · Pull Request #2108 · NativeScript/android

Description: Description Supersedes #2068 with a different approach to the same two crashes. Race on worker shutdown. RunMainThreadEntry read a worker's isolate from the callback cache, released cacheMutex_, and only then took a v8::Locker on it. A worker shutting down in that window (DestroyRuntime → Dispose) freed the isolate first, and the main thread crashed in v8::Locker::Initialize. #2068 fixed this by making the worker wait for in-flight main-thread holds before disposing. That keeps the isolate alive for a caller that will then only find its entry gone: the main thread still locks and enters a worker that was told to terminate, and teardown waits on main-thread progress. This PR drops the call instead: Each worker owns an IsolateGate (std::mutex + open), held by shared_ptr in the cache entry so it outlives the isolate. The main thread takes the gate's mutex, returns if the gate is closed, and releases it only once it owns the worker's Locker. Worker shutdown closes the gate before it takes its teardown Locker, while holding no Locker. Once closed, the main thread never touches the isolate. The worker never waits for the main thread beyond the Locker contention that already existed. Right after closing the gate, shutdown takes and releases the worker's Locker, which waits out a callback that already owned it. Without that, such a callback kept running beside the inspector teardown and the Java detach. The gate is per worker and never taken while holding that worker's Locker, so there is no lock-order cycle. A global mutex would deadlock against a worker that calls __runOnMainThread while holding its own Locker. Main-isolate entries (multithreaded JS) carry no gate and are unchanged. Throwing worker callbacks. Under uncaughtErrorPolicy: "throw", a worker callback's uncaught error was rethrown on the main thread as a Java exception. That exception resolved a handle from the worker isolate against the main one and crashed (SIGSEGV in NativeScriptException::ReThrowToJava). Worse, it would have taken the app down for an error that belongs to the worker. It now goes through the worker's own error path (CallWorkerScopeOnErrorHandle: the worker's onerror, then the parent's Worker object), as the worker's message dispatch already does. Under the default report policy nothing changes. Does your commit message include the wording below to reference a specific issue in this repo? No issue; supersedes #2068. Related Pull Requests #2068 (superseded) Does your pull request have unit tests? No new spec. The race window is a few instructions wide, and the throw policy can't run in the device suite because it crashes the app on purpose (see testUncaughtErrorPolicy.js). Verified manually with a focused repro on an arm64 API 35 emulator, with usleep(200000) injected in RunMainThreadEntry right after the entry lookup: Repro main this PR Worker posts __runOnMainThread(cb), busy-waits 50 ms, then close() (x5) SIGSEGV in v8::Locker::Initialize no crash, cb dropped uncaughtErrorPolicy: "throw", worker's __runOnMainThread callback throws SIGSEGV in NativeScriptException::ReThrowToJava parent Worker.onerror gets Uncaught Error: boom-from-worker-callback, app alive Worker posts a callback that busy-waits 300 ms, then close()s (no injected sleep) teardown continues while the callback runs (from the code, not measured) gate closes at +0 ms, callback runs +6 to +307 ms, teardown resumes at +307 ms The full device suite passes (runtestsAndVerifyResults: 1600/1600, rebased on #2113). Summary by CodeRabbit Bug Fixes Worker callbacks are safely discarded when a worker is shutting down, preventing them from running against a disposed runtime. Worker shutdown waits for in-flight main-thread callbacks before continuing cleanup. Uncaught exceptions from worker callbacks now follow the worker’s error-handling path instead of being raised as Java exceptions on the main thread. Callbacks from the main runtime retain their existing exception behavior.

Open Graph Description: Description Supersedes #2068 with a different approach to the same two crashes. Race on worker shutdown. RunMainThreadEntry read a worker's isolate from the callback cache, released cacheMutex_...

X Description: Description Supersedes #2068 with a different approach to the same two crashes. Race on worker shutdown. RunMainThreadEntry read a worker's isolate from the callback cache, released cacheMu...

Opengraph URL: https://github.com/NativeScript/android/pull/2108

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:574508da-dabe-2916-d021-5dc3578b3070
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD224:785A9:167DBA6:1C87EA4:6B013588
html-safe-nonce8996be25c69ee7bdf3b752285ebd46f7b67a690c8b8fd2bc9d846085a2e6589a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjI0Ojc4NUE5OjE2N0RCQTY6MUM4N0VBNDo2QjAxMzU4OCIsInZpc2l0b3JfaWQiOiI1OTAzODgwODg4ODk4MzY4OTA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacbbb7fce252745ba127f817248b19a1c1b04025e9b75d433946f68af1e8b70755
hovercard-subject-tagpull_request:5267546928
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2108/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altDescription Supersedes #2068 with a different approach to the same two crashes. Race on worker shutdown. RunMainThreadEntry read a worker's isolate from the callback cache, released cacheMutex_...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/pull/2108/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2108%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2108%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/pull/2108/files
Reloadhttps://github.com/NativeScript/android/pull/2108/files
Reloadhttps://github.com/NativeScript/android/pull/2108/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/android/tree/main
fix/run-on-main-thread-drophttps://github.com/NativeScript/android/tree/fix/run-on-main-thread-drop
Conversation 1 https://github.com/NativeScript/android/pull/2108
Commits 2 https://github.com/NativeScript/android/pull/2108/commits
Checks 8 https://github.com/NativeScript/android/pull/2108/checks
Files changed https://github.com/NativeScript/android/pull/2108/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2108/files
fix(worker): drop callbacks from closing workers https://github.com/NativeScript/android/pull/2108/files#top
Show all changes 2 commits https://github.com/NativeScript/android/pull/2108/files
6bf78a9 fix(worker): drop __runOnMainThread callbacks from a closing worker edusperoni Nov 11, 2026 https://github.com/NativeScript/android/pull/2108/commits/6bf78a96916ef21e7a5ef67a2bbe977865ff5866
2a24e42 fix(worker): wait out an in-flight main-thread callback before teardown edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2108/commits/2a24e423bf78f8c3aea73e0afb501ac1241f5153
Clear filters https://github.com/NativeScript/android/pull/2108/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2108/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2108/files
CallbackHandlers.cpp https://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
CallbackHandlers.h https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
Runtime.cpp https://github.com/NativeScript/android/pull/2108/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
WorkerWrapper.cpp https://github.com/NativeScript/android/pull/2108/files#diff-1344a5b85b9f266cab5024f2d52426ba56e3832c074d2c139fb560bcaaabfdc7
WorkerWrapper.h https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
test-app/runtime/src/main/cpp/CallbackHandlers.cpphttps://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
View file https://github.com/NativeScript/android/blob/2a24e423bf78f8c3aea73e0afb501ac1241f5153/test-app/runtime/src/main/cpp/CallbackHandlers.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2108/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
https://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
https://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
https://github.com/NativeScript/android/pull/2108/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
test-app/runtime/src/main/cpp/CallbackHandlers.hhttps://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
View file https://github.com/NativeScript/android/blob/2a24e423bf78f8c3aea73e0afb501ac1241f5153/test-app/runtime/src/main/cpp/CallbackHandlers.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2108/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
https://github.com/NativeScript/android/pull/2108/files#diff-1f7b413d95b12ea3b982950185ce4f7e56c5c02952d656a5dcc0ff8878e37722
test-app/runtime/src/main/cpp/Runtime.cpphttps://github.com/NativeScript/android/pull/2108/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
View file https://github.com/NativeScript/android/blob/2a24e423bf78f8c3aea73e0afb501ac1241f5153/test-app/runtime/src/main/cpp/Runtime.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2108/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2108/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
https://github.com/NativeScript/android/pull/2108/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
test-app/runtime/src/main/cpp/WorkerWrapper.cpphttps://github.com/NativeScript/android/pull/2108/files#diff-1344a5b85b9f266cab5024f2d52426ba56e3832c074d2c139fb560bcaaabfdc7
View file https://github.com/NativeScript/android/blob/2a24e423bf78f8c3aea73e0afb501ac1241f5153/test-app/runtime/src/main/cpp/WorkerWrapper.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2108/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2108/files#diff-1344a5b85b9f266cab5024f2d52426ba56e3832c074d2c139fb560bcaaabfdc7
https://github.com/NativeScript/android/pull/2108/files#diff-1344a5b85b9f266cab5024f2d52426ba56e3832c074d2c139fb560bcaaabfdc7
test-app/runtime/src/main/cpp/WorkerWrapper.hhttps://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
View file https://github.com/NativeScript/android/blob/2a24e423bf78f8c3aea73e0afb501ac1241f5153/test-app/runtime/src/main/cpp/WorkerWrapper.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2108/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
https://github.com/NativeScript/android/pull/2108/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
Please reload this pagehttps://github.com/NativeScript/android/pull/2108/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.