mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Resolve race condition in usage/teardown of EventEmitterWrapper
Summary: In stopSurface we destroy these EventEmitters which is not a threadsafe operation. Wrap usage and destruction of these wrappers to prevent crashes. This crash is caused by D29020768 (https://github.com/facebook/react-native/commit/25e8fbe8ffa1c91522e91819a781434093f8b759) which was landed to fix T92179998, which was in turn caused by D28938637 (https://github.com/facebook/react-native/commit/ac6d1982f4df55eca4da1cfc588dadc35bc005d0). Changelog: [internal] Reviewed By: sammy-SC, mdvacca Differential Revision: D29239828 fbshipit-source-id: 6be5acf4a24b82c75c13fe9f1d16a87cce5b7e00
This commit is contained in:
committed by
Facebook GitHub Bot
parent
257e83f664
commit
499ac1f14b
+16
-10
@@ -48,11 +48,13 @@ public class EventEmitterWrapper {
|
||||
* @param params {@link WritableMap} payload of the event
|
||||
*/
|
||||
public void invoke(@NonNull String eventName, @Nullable WritableMap params) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
synchronized (mHybridData) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
NativeMap payload = params == null ? new WritableNativeMap() : (NativeMap) params;
|
||||
invokeEvent(eventName, payload);
|
||||
}
|
||||
NativeMap payload = params == null ? new WritableNativeMap() : (NativeMap) params;
|
||||
invokeEvent(eventName, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,16 +66,20 @@ public class EventEmitterWrapper {
|
||||
*/
|
||||
public void invokeUnique(
|
||||
@NonNull String eventName, @Nullable WritableMap params, int customCoalesceKey) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
synchronized (mHybridData) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
NativeMap payload = params == null ? new WritableNativeMap() : (NativeMap) params;
|
||||
invokeUniqueEvent(eventName, payload, customCoalesceKey);
|
||||
}
|
||||
NativeMap payload = params == null ? new WritableNativeMap() : (NativeMap) params;
|
||||
invokeUniqueEvent(eventName, payload, customCoalesceKey);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (mHybridData != null) {
|
||||
mHybridData.resetNative();
|
||||
synchronized (mHybridData) {
|
||||
if (mHybridData != null) {
|
||||
mHybridData.resetNative();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user