mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
74608417df
commit
7929551623
+3
-3
@@ -47,7 +47,7 @@ public class EventEmitterWrapper {
|
||||
* @param eventName {@link String} name of the event to execute.
|
||||
* @param params {@link WritableMap} payload of the event
|
||||
*/
|
||||
public void invoke(@NonNull String eventName, @Nullable WritableMap params) {
|
||||
public synchronized void invoke(@NonNull String eventName, @Nullable WritableMap params) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class EventEmitterWrapper {
|
||||
* @param eventName {@link String} name of the event to execute.
|
||||
* @param params {@link WritableMap} payload of the event
|
||||
*/
|
||||
public void invokeUnique(
|
||||
public synchronized void invokeUnique(
|
||||
@NonNull String eventName, @Nullable WritableMap params, int customCoalesceKey) {
|
||||
if (!isValid()) {
|
||||
return;
|
||||
@@ -71,7 +71,7 @@ public class EventEmitterWrapper {
|
||||
invokeUniqueEvent(eventName, payload, customCoalesceKey);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
public synchronized void destroy() {
|
||||
if (mHybridData != null) {
|
||||
mHybridData.resetNative();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user