René's URL Explorer Experiment


Title: fix: keep the Worker object rooted until its thread ends, and report the end as nsworkerended by edusperoni · Pull Request #2044 · NativeScript/android · GitHub

Open Graph Title: fix: keep the Worker object rooted until its thread ends, and report the end as nsworkerended by edusperoni · Pull Request #2044 · NativeScript/android

X Title: fix: keep the Worker object rooted until its thread ends, and report the end as nsworkerended by edusperoni · Pull Request #2044 · NativeScript/android

Description: Stacked on #2043 (feat/worker-threads) — merge that first. What this fixes terminate() reset the Worker object's Persistent and dropped the registry entry synchronously, while the worker thread was still winding down. From that moment the wrapper was unreachable from native, the end of the worker was unobservable from JS, and any message the worker had already queued on the parent's loop was discarded when it arrived. Android vs iOS lifetime — what was verified before porting The iOS change is largely about replacing finalizer resurrection with reachability. Android never had that problem, so most of it does not apply: The Worker object is already a strong root, from construction. WorkerWrapper::poWorker_ is new Persistent(parentIsolate, workerObject) (WorkerWrapper.cpp) and is never made weak. There is no RootWorkerObject/UnrootWorkerObject to add. The Worker object is not an ObjectManager object. CallbackHandlers::NewThreadCallback takes args.This() of the plain FunctionTemplate installed in Runtime::PrepareV8Runtime (Runtime.cpp, the Worker constructor block) and hands it to the wrapper; nothing registers it with ObjectManager or marks it for GC. So none of iOS's DataWrapper/ObjectManager refuse-and-re-weaken work has an Android counterpart. The wrapper itself is shared_ptr-owned by the registry and by the detached thread (Start() captures shared_from_this() and BackgroundLooper holds it for the thread's whole life), so this cannot die under the thread. iOS's "read everything before publishing isDisposed_" hardening exists because a tearing-down iOS parent can delete the wrapper concurrently; that cannot happen here, and it is left alone. Worker-thread posts already reach the parent only through its event loop. parentTasks_ is a std::weak_ptr captured on the parent's thread at construction, and PostMessageToParent, PassUncaughtExceptionFromWorkerToParent and the thread-exit post all go through it. The only reads of the parent isolate's runtime slot (Runtime::GetRuntime(parentIsolate)) happen inside lambdas that run on the parent's thread. Nothing was wrong; nothing changed. The change CallbackHandlers::WorkerObjectTerminateCallback no longer calls WorkerWrapper::ClearWorkerOnParent(id). terminate() only starts the wind-down. WorkerWrapper::BackgroundLooper's final post to the parent's loop now runs a new WorkerWrapper::NotifyThreadEndedOnParent(workerId): on the parent's thread, with the parent isolate locked and entered, it resolves the wrapper by id, takes the Worker object out of poWorker_, calls WorkerEvents::EmitEnded under a TryCatch (a throwing listener is reported exactly as FireErrorOnParentWorkerObject/FireMessageOnParentWorkerObject report one — ContainUncaughtCallbackException then ReportFromEventLoopEntry), and only then calls ClearWorkerOnParent. WorkerEvents::EmitEnded mirrors EmitError's shape: a third emitEnded callout cached in WorkerEventsState at WorkerEvents::Init. js/worker-events.js gains emitEnded(), which dispatches a plain Event("nsworkerended") on the Worker object. js/node-worker-threads.js: the shim's Worker listens for nsworkerended and reports the exit from there. exit (code 0) is emitted exactly once, for a self-close() as much as for terminate(), and terminate() now resolves from the same notification instead of off a microtask, so nothing the worker sent can arrive after exit. A parent that is itself tearing down (TerminateChildren → ClearWorkerOnParent on the parent's thread) or whose loop is gone (expired parentTasks_) never delivers the notification. That is deliberate, matches iOS, and is documented as best effort. Consumer audit for the removed clear. Nothing relied on the persistent being empty after terminate() for correctness: PostMessageToParent already returns early on isTerminating_; every error source is gated at the point of forwarding (CallWorkerScopeOnErrorHandle returns early on IsTerminating(), the unhandled-rejection path in NativeScriptException.cpp checks IsTerminating()/IsDisposed(), and BackgroundLooper's catch checks !isTerminating_), so no error from a terminated worker reaches the parent; the isTerminated private only guards a double terminate(); FireMessageOnParentWorkerObject/FireErrorOnParentWorkerObject keep their empty-persistent guards for the teardown paths that still clear early. The one observable change is the intended one: a message the worker queued before terminate() is now delivered instead of being dropped on arrival, and it is delivered before nsworkerended. Tests New Android-only specs in test-app/app/src/main/assets/app/tests/testWorkerLifetime.js (wired in mainpage.js), with workerLifetimeCloseWorker.js and messaging/deadlockChild.js / messaging/deadlockParent.js: a live Worker survives GC as a WeakMap key (the ephemeron repro, kept as a regression guard; collections are driven from a task via __collect({ execution: "async" }) so conservative stack scanning does not keep the workers alive) an unreferenced live Worker still answers messages a terminated Worker becomes collectable — observed after nsworkerended, since the root outlives terminate() by design a Worker that closed itself becomes collectable node:worker_threads: exit exactly once on self-close(); exit exactly once on terminate(), after the thread ended, with terminate() resolving after it and a second terminate() resolving immediately a terminated worker whose dropped message sentinels a port it owns still ends Full device suite on a Pixel_3a_API_36 arm64 emulator: 1398 specs, 0 failures, 4 skipped (baseline on feat/worker-threads was 1391/0/4; the 7 new specs all ran and passed). npm run lint clean. Deviations from iOS (ab72efc2) Not ported: DataWrapper.h, ObjectManager.mm, RootWorkerObject/UnrootWorkerObject, EndWrapperLifetime, selfRef_. Android's persistent is strong from construction and the Worker object is not an ObjectManager object, so there is no weak handle to clear and no resurrection branch to take it off. The wrapper is kept alive by shared_ptrs, so iOS's atomic liveness token is unnecessary — the notification resolves the wrapper through the id-keyed registry instead. Not ported: PostToRuntimeLoop → PostToLoop / mainLoop_. Android already captures parentTasks_ as a weak_ptr on the parent's thread; the isolate-slot read iOS was removing does not exist here. Not ported: the isDisposed_ publication reordering. The thread owns a shared_ptr to the wrapper, so nothing can delete it mid-teardown. EmitEnded lives in WorkerEvents, not Worker. Android splits the worker-events callouts into WorkerEvents.{h,cpp}; that is where EmitMessage/EmitError already are. docs/knowledge/v8-resurrecting-finalizers.md has no Android counterpart (docs/knowledge/ holds only v8-14-migration.md), so that hunk is skipped. The js/README.md listener-bag rule is reworded to the same effect without referring to a patch document this repo does not carry. Docs say "from the moment it is constructed" where iOS says "from the moment its thread starts", because Android's persistent is strong from construction rather than from Start(). Tests are in Android style (var/function, jasmine done) and bump jasmine.DEFAULT_TIMEOUT_INTERVAL to 30s the way the other worker suites do; the fixed waits in the node:worker_threads specs are 2000 ms rather than iOS's 800 ms for emulator slowness. The two collectability specs additionally gate on nsworkerended before observing the WeakRef, which iOS approximates with a fixed delay. Mirrors NativeScript/ios#456. Summary by CodeRabbit Bug Fixes Workers now remain available while termination is in progress and become eligible for garbage collection after their thread ends. The exit event is reported once after the worker finishes, with exit code 0. Calls to terminate() now resolve when shutdown completes rather than immediately. Documentation Clarified when worker exit notifications occur, how termination results are reported, and how worker lifetime relates to garbage collection.

Open Graph Description: Stacked on #2043 (feat/worker-threads) — merge that first. What this fixes terminate() reset the Worker object's Persistent and dropped the registry entry synchronously, while the worker thread...

X Description: Stacked on #2043 (feat/worker-threads) — merge that first. What this fixes terminate() reset the Worker object's Persistent and dropped the registry entry synchronously, while the worker th...

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

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:f39c3a4b-d0b5-e17c-fbc2-5782f3be743d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD362:1F8F:92FA15:C06A3F:6B0132C5
html-safe-noncef9c612173da58f60ad04872d7ef069d8ed57e3ec208f3796448733898ced05a7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzYyOjFGOEY6OTJGQTE1OkMwNkEzRjo2QjAxMzJDNSIsInZpc2l0b3JfaWQiOiI3NDM4NjQ0NzU1ODU0MDc4NjYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac6175c02b440c1541b74917d13870b5e94ebd188e78ef430074d3bf97a75a8358
hovercard-subject-tagpull_request:4509855144
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/2044/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:altStacked on #2043 (feat/worker-threads) — merge that first. What this fixes terminate() reset the Worker object's Persistent and dropped the registry entry synchronously, while the worker thread...
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/2044/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2044%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%2F2044%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/2044/files
Reloadhttps://github.com/NativeScript/android/pull/2044/files
Reloadhttps://github.com/NativeScript/android/pull/2044/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
feat/worker-threadshttps://github.com/NativeScript/android/tree/feat/worker-threads
fix/worker-strong-lifetimehttps://github.com/NativeScript/android/tree/fix/worker-strong-lifetime
Conversation 1 https://github.com/NativeScript/android/pull/2044
Commits 1 https://github.com/NativeScript/android/pull/2044/commits
Checks 13 https://github.com/NativeScript/android/pull/2044/checks
Files changed https://github.com/NativeScript/android/pull/2044/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2044/files
fix: keep the Worker object rooted until its thread ends, and report the end as nsworkerended https://github.com/NativeScript/android/pull/2044/files#top
Show all changes 1 commit https://github.com/NativeScript/android/pull/2044/files
59edaa4 fix: keep the Worker object rooted until its thread ends, and report … edusperoni Sep 11, 2026 https://github.com/NativeScript/android/pull/2044/commits/59edaa4a5da8465e6d43a1c7a1715d2a91bd99f5
Clear filters https://github.com/NativeScript/android/pull/2044/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2044/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2044/files
worker-threads.md https://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
mainpage.js https://github.com/NativeScript/android/pull/2044/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
deadlockChild.js https://github.com/NativeScript/android/pull/2044/files#diff-c647851004bf5e84193038eeee500ba6249c5d6966d40d701d1c34559af266d6
deadlockParent.js https://github.com/NativeScript/android/pull/2044/files#diff-4e3dcd6fa1f241f0a011d1357dfe8006c4d0cfc4b672931dc3106807e1d2215e
testWorkerLifetime.js https://github.com/NativeScript/android/pull/2044/files#diff-0d7cf4e322ca69fd8c4ff4d5e36e27f89dca9bde3aae096fbacf8c590d043aee
workerLifetimeCloseWorker.js https://github.com/NativeScript/android/pull/2044/files#diff-7cfc7bc9a7642ee6c8a04b19edb9659b9038e9a8600cd04b4f06d7c0430b6dd0
CallbackHandlers.cpp https://github.com/NativeScript/android/pull/2044/files#diff-a784229ab7689cd9ce3d502557091158b2943269fad47c1891a15a07c355500e
WorkerEvents.cpp https://github.com/NativeScript/android/pull/2044/files#diff-2e0498536ef0cddf4c00cfdacbfca48ca3b0c16abfdd51f8b86779cd02ec76ab
WorkerEvents.h https://github.com/NativeScript/android/pull/2044/files#diff-b7d0c8668fa7cce6d8984b50636b8ce6e6752a9b7975c022d12c739816f7b350
WorkerWrapper.cpp https://github.com/NativeScript/android/pull/2044/files#diff-1344a5b85b9f266cab5024f2d52426ba56e3832c074d2c139fb560bcaaabfdc7
WorkerWrapper.h https://github.com/NativeScript/android/pull/2044/files#diff-94a94304b1fb4dd29852688ec48aa5583d6b2d6017d149c731cf5f191bf08a2e
README.md https://github.com/NativeScript/android/pull/2044/files#diff-751334ceaf7705bb581ba52ea1f45b471007312e7194253725e94c12eb8f22fe
events.js https://github.com/NativeScript/android/pull/2044/files#diff-15bc07870a0153b6b63d42bcfe4c35c81696d01b681d4c816f2206f5cea57f38
node-worker-threads.js https://github.com/NativeScript/android/pull/2044/files#diff-9b33730ae64035954c1f38349d6cc5aad4133b2b9e9df06cd680893c3c3b596e
worker-events.js https://github.com/NativeScript/android/pull/2044/files#diff-a166ef75929b5a609376de9eff572a04ab954d45e78106dc71771630d9429ef0
docs/worker-threads.mdhttps://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
View file https://github.com/NativeScript/android/blob/59edaa4a5da8465e6d43a1c7a1715d2a91bd99f5/docs/worker-threads.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2044/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
https://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
https://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
https://github.com/NativeScript/android/pull/2044/files#diff-81eca78391cf7755356eded4d70ab6d0d972af537aecc12964277307636d868e
test-app/app/src/main/assets/app/mainpage.jshttps://github.com/NativeScript/android/pull/2044/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
View file https://github.com/NativeScript/android/blob/59edaa4a5da8465e6d43a1c7a1715d2a91bd99f5/test-app/app/src/main/assets/app/mainpage.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2044/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2044/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
https://github.com/NativeScript/android/pull/2044/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
test-app/app/src/main/assets/app/tests/messaging/deadlockChild.jshttps://github.com/NativeScript/android/pull/2044/files#diff-c647851004bf5e84193038eeee500ba6249c5d6966d40d701d1c34559af266d6
View file https://github.com/NativeScript/android/blob/59edaa4a5da8465e6d43a1c7a1715d2a91bd99f5/test-app/app/src/main/assets/app/tests/messaging/deadlockChild.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2044/{{ revealButtonHref }}
test-app/app/src/main/assets/app/tests/messaging/deadlockParent.jshttps://github.com/NativeScript/android/pull/2044/files#diff-4e3dcd6fa1f241f0a011d1357dfe8006c4d0cfc4b672931dc3106807e1d2215e
View file https://github.com/NativeScript/android/blob/59edaa4a5da8465e6d43a1c7a1715d2a91bd99f5/test-app/app/src/main/assets/app/tests/messaging/deadlockParent.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2044/{{ revealButtonHref }}
Please reload this pagehttps://github.com/NativeScript/android/pull/2044/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2044/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.