hyochan / react-native-audio-recorder-player

react-native native module for audio recorder and player.
MIT License
681 stars 203 forks source link

Fix race conditions in iOS #608

Closed jbaudanza closed 3 weeks ago

jbaudanza commented 1 month ago

There were a few race conditions in the multithreaded code in RNAudioRecorderPlayer.swift.

self.recordTimer is set from the main thread. If caller invokes startRecoder and then subsequently stopRecorder, there is no guarantee that self.recordTimer will be set in time. This will result in "ghost" rn-recordback events being sent to the React Native thread.

To resolve this, this PR creates the timers on the react-native bridge thread, and then manually adds them to the main thread's run loop.

self.audioRecorder has a similar issue. It's created on the main thread, but then stopPlayer checks its value on the bridge thread. To resolve the race condition here, this PR dispatches the check on the main thread