Skip to content

test: destroy native Promise listeners on another thread - #1993

Open
mrousavy wants to merge 1 commit into
v1from
mrousavy/v1-jni-release-thread-tests
Open

mrousavy wants to merge 1 commit into
v1from
mrousavy/v1-jni-release-thread-tests

Conversation

@mrousavy

Copy link
Copy Markdown
Member

JSI lets a JS engine destroy a native function's state on any thread. Hermes' concurrent GC does that on its own thread, which the JVM never attached on Android.

The test runtime gets destroyOnBackgroundThread(fn). It takes the native state out of a native JS function and destroys it on a new thread. Two Memory cases use it on the then and catch listeners Nitro adds to a JS Promise passed to awaitAndGetPromise(...): once while the Promise is pending, and once after it resolved.

C++ and Swift pass. Kotlin crashes with Unable to retrieve jni environment. Is the thread attached?, thrown from GlobalReferenceAllocator::deleteReference while the listeners release the Kotlin result. Android CI stays red until the PR on top of this one.

Callbacks aren't covered. A Kotlin callback returned to JS is also owned by its Java Callback_*_cxx object, so which owner releases it last depends on Java GC.

🤖 Generated with Claude Code

JSI lets a JS engine destroy a native function's state on any thread.
Hermes' concurrent GC does that on its own background thread, which is
not attached to the JVM on Android.

The test runtime now has `destroyOnBackgroundThread(fn)`, which takes a
native function's state and destroys it on a new thread. Two cases use it
on the `then` and `catch` listeners Nitro adds to a JS Promise passed to
`awaitAndGetPromise(...)`, once while pending and once after it resolved.

Kotlin crashes on both: the listeners release JNI global references and
reject the Kotlin Promise without an attached thread.
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
nitro-docs Skipped Skipped Oct 23, 2026 12:14pm UTC

Request Review

@mrousavy
mrousavy changed the base branch from v1 to main October 23, 2026 12:14
@mrousavy
mrousavy added this pull request to stack #1995 October 23, 2026 12:14
@mrousavy
mrousavy removed this pull request from stack #1995 October 23, 2026 12:14
@mrousavy
mrousavy changed the base branch from main to v1 October 23, 2026 12:14
@mrousavy
mrousavy added this pull request to stack #1996 October 23, 2026 12:14

This branch was previously deployed

1 inactive deployment
Preview — 65aabbda Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant