Title: Worker teardown: AB-BA deadlock between main and worker V8 isolate locks (constrained-core/CI) · Issue #397 · NativeScript/ios · GitHub
Open Graph Title: Worker teardown: AB-BA deadlock between main and worker V8 isolate locks (constrained-core/CI) · Issue #397 · NativeScript/ios
X Title: Worker teardown: AB-BA deadlock between main and worker V8 isolate locks (constrained-core/CI) · Issue #397 · NativeScript/ios
Description: Summary The runtime unit-test suite intermittently deadlocks during the TNS Workers "no crash during or after runtime teardown on iOS" worker stress spec. It does not reproduce on multi-core dev machines, but reproduces reliably on the c...
Open Graph Description: Summary The runtime unit-test suite intermittently deadlocks during the TNS Workers "no crash during or after runtime teardown on iOS" worker stress spec. It does not reproduce on multi-core dev ma...
X Description: Summary The runtime unit-test suite intermittently deadlocks during the TNS Workers "no crash during or after runtime teardown on iOS" worker stress spec. It does not reproduce on multi-c...
Opengraph URL: https://github.com/NativeScript/ios/issues/397
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Worker teardown: AB-BA deadlock between main and worker V8 isolate locks (constrained-core/CI)","articleBody":"## Summary\n\nThe runtime unit-test suite intermittently **deadlocks** during the `TNS Workers` \"no crash during or after runtime teardown on iOS\" worker stress spec. It does **not** reproduce on multi-core dev machines, but reproduces reliably on the constrained CI runner. Root cause is a genuine **AB-BA deadlock between two V8 isolate locks** (the main isolate and a worker isolate) — a real (if rare) latent runtime issue, not just a test artifact.\n\nThe spec is **quarantined at the harness level** (a `specFilter` entry in `TestRunner/app/Infrastructure/Jasmine/jasmine-2.0.1/boot.js`) so CI is green; this issue tracks the proper runtime fix and re-enabling the spec.\n\n## The deadlock (proven from native stacks)\n\nCaptured by sampling the hung `TestRunner` app process on CI (10 snapshots, identical cycle in each):\n\n**Main thread** — holds the **main** isolate lock (running JS), is in the spec's 1ms `setTimeout` loop posting `'send-to-worker'`:\n\n```\n__NSFireTimer → JS produceMessageInLoop\n → -[NSNotificationCenter postNotificationName:object:userInfo:]\n → __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ (worker's queue:nil observer block)\n → tns::ArgConverter::MethodCallback → v8::Locker::Locker(workerIsolate)\n → __psynch_mutexwait // BLOCKED waiting for the worker isolate lock\n```\n\n**Worker thread** — holds **its own** isolate lock (loading `TeardownCrashWorker.js`), triggers a main-extended class's `+initialize`:\n\n```\nWorkerWrapper::BackgroundLooper → Runtime::RunModule → ... → ObjC msgSend\n → initializeNonMetaClass → CALLING_SOME_+initialize_METHOD\n → block in ClassBuilder::RegisterNativeTypeScriptExtendsFunction (NativeScript/runtime/ClassBuilder.mm:266)\n → v8::Locker::Locker(mainIsolate)\n → __psynch_mutexwait // BLOCKED waiting for the main isolate lock\n```\n\n(A third thread is a secondary victim, blocked on the ObjC class-initialization `os_unfair_lock` held by the stuck worker.)\n\nSo: **main holds main-lock / wants worker-lock; worker holds worker-lock / wants main-lock.** Neither can proceed. It only manifests when those two windows overlap, which is why fast machines miss it and constrained CI hits it.\n\n## Why each side crosses isolates\n\n- **main → worker**: the worker registered an `NSNotificationCenter` observer with a **nil queue**, so the block runs synchronously on the *posting* (main) thread; NativeScript marshals it into the worker isolate, taking the worker's `v8::Locker`.\n- **worker → main**: `ClassBuilder::RegisterNativeTypeScriptExtendsFunction` installs a `+initialize` IMP that captures the **defining** isolate and does `v8::Locker locker(isolate)` ([ClassBuilder.mm:262-296](../blob/main/NativeScript/runtime/ClassBuilder.mm#L262)). `+initialize` fires lazily on whichever thread first messages the class — here a worker thread first-touches a main-defined extended class, so the worker runs `+initialize` and locks the **main** isolate.\n\n## Reproduction conditions\n\n- Constrained cores (CI runner; not reproducible on many-core dev machines).\n- A worker observing a main-thread notification with a nil queue, while the worker is still initializing/first-touching a main-isolate-extended class.\n- This pattern is unusual but **possible in production**, so the fix matters beyond CI.\n\n## Candidate fix directions (both deep; need a real repro harness + review)\n\n1. **worker → main side** — avoid running a foreign isolate's `+initialize` from a worker thread (e.g. seed/force initialization on the defining isolate's thread at registration time, or make the IMP defer to the defining isolate's runloop). Risk: class-extension / `ObjCExposedMethods` timing.\n2. **main → worker side** — invoke a worker-owned callback (e.g. a nil-queue notification block) on the worker's runloop instead of synchronously on the posting thread. Risk: changes synchronous-callback semantics app-wide.\n\n## Diagnostics\n\nNative-stack capture on hang is now wired into CI (`.github/scripts/sample-hung-app.sh`, uploaded as the `test-diagnostics` artifact), and the in-app Jasmine progress beacon reports the last suite to the XCTest harness — so any future suite hang is self-diagnosing.\n","author":{"url":"https://github.com/NathanWalker","@type":"Person","name":"NathanWalker"},"datePublished":"2026-06-27T16:37:44Z","url":"https://github.com/NativeScript/ios/issues/397"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4ebaed58-4ca9-2e27-6ec9-36eff137af4c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E282:3DD488:19E4F68:20D7D02:6B014C2F |
| html-safe-nonce | 548b02cad4b542cc4a61d379d8f11237a664ba18c7ec2f257a16ce84b7483afe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjgyOjNERDQ4ODoxOUU0RjY4OjIwRDdEMDI6NkIwMTRDMkYiLCJ2aXNpdG9yX2lkIjoiNDM2MDY4NDYwODU0ODU2NzUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b8d54378487eb41ff464155e0888555125abf4e378b8d554aa62d0400383188d |
| hovercard-subject-tag | issue:4759117197 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/ios/397/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5731edf1fe4020f0b407ffc441a3f26e3827dca0627c3d6532b60f3d8bf11b24/NativeScript/ios/issues/397 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5731edf1fe4020f0b407ffc441a3f26e3827dca0627c3d6532b60f3d8bf11b24/NativeScript/ios/issues/397 |
| og:image:alt | Summary The runtime unit-test suite intermittently deadlocks during the TNS Workers "no crash during or after runtime teardown on iOS" worker stress spec. It does not reproduce on multi-core dev ma... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NathanWalker |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/ios git https://github.com/NativeScript/ios.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 172934359 |
| octolytics-dimension-repository_nwo | NativeScript/ios |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 172934359 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/ios |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width