[ReactNative][Crash] stop dispatching checkout events into a dead runtime - #602
Draft
kieran-osgood-shopify wants to merge 1 commit into
Conversation
### TLDR A checkout sheet can outlive the React runtime. A lifecycle event from that orphaned sheet reached a freed C++ emitter and killed the process with `SIGSEGV`. ### What `ShopifyCheckoutKitModule` now overrides `invalidate()` and releases the checkout listener, so a sheet that survives teardown cannot dispatch into a runtime that is going away. `emitOnDispatch` is also routed through `emitWhenReactInstanceIsActive`, which drops the event when `hasActiveReactInstance()` is false. That guard is the backstop for any path that skips `invalidate()`. Every lifecycle event and every protocol event shares one `DispatchHandle`, so this is a single choke point. `DispatchHandle.released` is a Java boolean and says nothing about the C++ emitter behind `emitOnDispatch`, so the Java-side release alone was not enough. `onCatalystInstanceDestroy` is deprecated for removal, so `invalidate()` is the supported teardown hook. ### How to test In the React Native sample, open several checkout sheets quickly, reload the JS bundle, then press Back repeatedly. | | Before | After | | --- | --- | --- | | Native crashes (new tombstones) | 3 | 0 | | Process restarts | 3 | 0 | The dangerous path still runs after the fix, so the reproduction stays valid: the log shows `Destroying ReactInstance`, then `onCheckoutCanceled` from the orphaned sheet 7 s later. A probe build confirmed the ordering, with `invalidate()` arriving while the listener was still live. The baseline tombstone records `SIGSEGV` / `SEGV_MAPERR` inside libc++'s `string -> shared_ptr<IAsyncEventEmitter>` map, below `NativeShopifyCheckoutKitSpec.emitOnDispatch`, `DispatchHandle.invoke`, and `CustomCheckoutListener.onCheckoutDismissed`. No unit test accompanies this change. The failure is a native use-after-free across the JNI boundary, which a Robolectric test cannot reach, so the device reproduction above is the evidence. Releasing the listener at the existing dismiss site is deferred to the PR that bumps the native SDK, because this module still stores a `CheckoutKitDialog`. Assisted-By: devx/c27c154c-e79d-4f1f-9300-c3258c6f34f9
Contributor
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes are you making?
There was a crash on rn-android due to accessing react activity after its disposed, this manifested when closing the sheet
How to test
Open and close the sheet multiple times on main and observe the crash, on this tophat build it no longer happens
Before you merge
Important
platforms/swift/README.mdand/orplatforms/android/README.md)Releasing a new Swift version?
ShopifyCheckoutKit.podspecplatforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swiftplatforms/swift/README.md(major version only)Releasing a new Embedded Checkout Protocol version?
embeddedCheckoutProtocolAndroidinplatforms/android/gradle/libs.versions.tomlprotocol/languages/kotlin/embedded-checkout-protocol/api/embedded-checkout-protocol.apiif the public API changedReleasing a new Android version?
checkoutKitAndroidinplatforms/android/gradle/libs.versions.tomlplatforms/android/README.mdTip
See the Contributing documentation for the full release process per platform.