Skip to content

Commit 7929551

Browse files
luluwu2032facebook-github-bot
authored andcommitted
Make mHybridData thread safe for EventEmitterWrapper
Summary: In T94154173, when calling ```EventEmitterWrapper->invoke()```, hybrid function ```invokeEvent``` is null, even if we checked that ```mHybridData``` is valid before calling ```invokeEvent```. **Theory:** ```invoke()``` is called from ```mqt_js``` thread, ```desotry()``` is called from ```main``` thread, which cause multi-thread access of```mHybridData```. So if ```desotry()``` is called after ```isValid()``` check and before calling ```invokeEvent()```, ```invokeEvent``` could be destroyed and is null. I can reproduce with above theory: {F633411001} **Fix:** Make functions synchronized so ```mHybridData``` can be thread safe. Changelog: [Android][Fixed] - Make mHybridData thread safe Reviewed By: RSNara Differential Revision: D29792453 fbshipit-source-id: 8b4c754d53ece933be7b2cf99c6cd026b39e24ad
1 parent 7460841 commit 7929551

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/events/EventEmitterWrapper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private native void invokeUniqueEvent(
4747
* @param eventName {@link String} name of the event to execute.
4848
* @param params {@link WritableMap} payload of the event
4949
*/
50-
public void invoke(@NonNull String eventName, @Nullable WritableMap params) {
50+
public synchronized void invoke(@NonNull String eventName, @Nullable WritableMap params) {
5151
if (!isValid()) {
5252
return;
5353
}
@@ -62,7 +62,7 @@ public void invoke(@NonNull String eventName, @Nullable WritableMap params) {
6262
* @param eventName {@link String} name of the event to execute.
6363
* @param params {@link WritableMap} payload of the event
6464
*/
65-
public void invokeUnique(
65+
public synchronized void invokeUnique(
6666
@NonNull String eventName, @Nullable WritableMap params, int customCoalesceKey) {
6767
if (!isValid()) {
6868
return;
@@ -71,7 +71,7 @@ public void invokeUnique(
7171
invokeUniqueEvent(eventName, payload, customCoalesceKey);
7272
}
7373

74-
public void destroy() {
74+
public synchronized void destroy() {
7575
if (mHybridData != null) {
7676
mHybridData.resetNative();
7777
}

0 commit comments

Comments
 (0)