Avoid duplicate destroy on same thread (#38233)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Lulu Wu
2023-07-10 13:37:34 -07:00
committed by Facebook GitHub Bot
parent d491674201
commit 43f7781c87
@@ -1415,6 +1415,13 @@ public class ReactHost implements ReactHostInterface {
raiseSoftException(method, reason, ex);
synchronized (mReactInstanceTaskRef) {
// Prevent re-destroy when ReactInstance has been reset already, which could happen when
// calling destroy multiple times on the same thread
ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
if (reactInstance == null) {
return;
}
// Retain a reference to current ReactContext before de-referenced by mReactContextRef
final ReactContext reactContext = getCurrentReactContext();