Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ public void updateAudioDeviceState() {
private WritableMap getAudioDeviceStatusMap() {
WritableMap data = Arguments.createMap();
String audioDevicesJson = "[";
for (AudioDevice s: audioDevices) {
for (AudioDevice s: new ArrayList<>(audioDevices)) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review — both points are valid.

  1. Compile error: right, java.util.ArrayList was missing. Fixed by adding the import.
  2. Snapshot doesn't fully prevent CME: agreed. The root cause is that audioDevices is a plain HashSet mutated from multiple threads —start() / chooseAudioRoute() run on the RN bridge thread while updateAudioDeviceState() runs on the UI thread, so even constructing the snapshot iterates a concurrently-modified set.

To fix it properly (and keep the change minimal), I switched audioDevices from HashSet to ConcurrentHashMap.newKeySet(). Iteration / snapshot construction is then weakly consistent and never throws CME. Since the field was previously reassigned (audioDevices = newAudioDevices), I changed that to clear() + addAll() so the concurrent set is updated in place rather than swapped out from under concurrent readers.

The new ArrayList<>(audioDevices) snapshot is retained so the JSON payload reflects a single point-in-time view rather than a live set.

audioDevicesJson += "\"" + s.name() + "\",";
}

Expand Down