Fix concurrent consumers issue with ReactMarker (#38710)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38710

Fix a race condition when multiple consumers try to access ReactMarker and trigger calls to native module. Even though ReactMarker uses `ConcurrentLinkedQueue`, the loop itself could race and cause NPE.

Changelog:
[Android][Fixed] - Fix race condition with ReactMarker calls to its native module

Reviewed By: rshest

Differential Revision: D47933993

fbshipit-source-id: a56e5e4f3564922d534235991da5b6842248bf24
This commit is contained in:
Xin Chen
2023-08-01 12:19:17 -07:00
committed by Facebook GitHub Bot
parent 743799078b
commit 6ab062dfec
@@ -193,8 +193,8 @@ public class ReactMarker {
nativeLogMarker(name.name(), now);
// Then send all cached native ReactMarkers
while (!sNativeReactMarkerQueue.isEmpty()) {
ReactMarkerRecord record = sNativeReactMarkerQueue.poll();
ReactMarkerRecord record;
while ((record = sNativeReactMarkerQueue.poll()) != null) {
nativeLogMarker(record.getMarkerName(), record.getMarkerTime());
}
} else {