Skip to content

Commit

Permalink
Avoid duplicate destroy on same thread (#38233)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Lulu Wu authored and facebook-github-bot committed Jul 10, 2023
1 parent d491674 commit 43f7781
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,13 @@ private void oldDestroy(String reason, @Nullable Exception ex) {
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();

Expand Down

0 comments on commit 43f7781

Please sign in to comment.