Skip to content

Commit 43f7781

Browse files
Lulu Wufacebook-github-bot
Lulu Wu
authored andcommitted
Avoid duplicate destroy on same thread (facebook#38233)
Summary: Pull Request resolved: facebook#38233 When call ReactHost.destroy multiple times on same thread, the synchronization we have now can not protect us from concurrent issues such as ```ConcurrentModificationException```, to avoid this case this diff checks if ReactInstance has been reset, if so it means an early destroy has been called and we should not destroy again. Changelog: [Android][Changed] - Avoid duplicate destroy on same thread Reviewed By: fkgozali Differential Revision: D47276191 fbshipit-source-id: 2291b89cb980ca762abddb835e703abd095a93b3
1 parent d491674 commit 43f7781

File tree

1 file changed

+7
-0
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless

1 file changed

+7
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactHost.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,13 @@ private void oldDestroy(String reason, @Nullable Exception ex) {
14151415
raiseSoftException(method, reason, ex);
14161416

14171417
synchronized (mReactInstanceTaskRef) {
1418+
// Prevent re-destroy when ReactInstance has been reset already, which could happen when
1419+
// calling destroy multiple times on the same thread
1420+
ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
1421+
if (reactInstance == null) {
1422+
return;
1423+
}
1424+
14181425
// Retain a reference to current ReactContext before de-referenced by mReactContextRef
14191426
final ReactContext reactContext = getCurrentReactContext();
14201427

0 commit comments

Comments
 (0)