You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 80c0723
Browse filesBrowse the repository at this point in the historyBrowse files
fix(runtime): avoid cross-isolate adapter and block teardown deadlocks
The collection adapters (DictionaryAdapter, ArrayAdapter, NSDataAdapter)
and the JS block dispose helper take their isolate's Locker on whatever
thread drops the last native reference. When that thread is inside another
isolate, it waits for one isolate's Locker while holding the other's, and
the two can deadlock:
- the main thread, inside a JS task, calls a native API that invokes a
callback registered by a worker, and waits for the worker's Locker;
- the worker's thread is collecting, and a finalizer releases an object
holding an adapter or a block that belongs to the main isolate, whose
teardown waits for the main isolate's Locker.
A notification posted from the main isolate with a JS object as userInfo,
observed by a block registered in a worker, is enough: the worker ends up
with the last reference to each notification.
IsolateWrapper::HandOffTeardown posts such a teardown to the owning
isolate's loop when the calling thread is inside another isolate and does
not hold the owner's Locker. If the loop drops the entry while shutting
down, the entry runs it; if the loop refuses the post, a dispatch queue
runs it with no isolate lock held.
Adapters: -dealloc hands itself off and returns without freeing anything;
the object stays allocated until it runs again on its own isolate. The
claim an adapter attaches to its JS object holds the adapter weakly, so
marshalling the object either takes a reference to a live adapter or, once
its last release has started, detaches the dead claim and builds a fresh
adapter that attaches its own. Only the adapter frees
its claim: retiring the JS object, including __releaseNativeCounterpart,
no longer releases the adapter. Adapter methods and teardown pin the
isolate before waiting for its Locker and check it again under the lock.
Blocks: libclosure frees a block as soon as its dispose helper returns, so
the helper first clears the address cached in the function's BlockWrapper,
under a mutex that reuse of the cached block also takes, and only then
hands off the cleanup that needs the isolate.
The ns:worker_threads specs get the 30 second startup bound the other
worker suites use; the utility-priority worker did not always start within
the default 5 seconds on CI.
0 commit comments