client-sdk-flutter icon indicating copy to clipboard operation
client-sdk-flutter copied to clipboard

[bug] possible race condition in LocalParticipant.setSourceEnabled

Open holzgeist opened this issue 1 year ago • 1 comments

Describe the bug

We enable/disable camera and microphone of the local participant in a callback whenever our call state changes. Sometimes we experienced duplicated audio and/or video streams. It turns out, while dart is single-threaded, due to its async nature, race conditions are still possible. Specifically if LocalParticipant.setSourceEnabled (via setCameraEnabled/setMicrophoneEnabled) is called concurrently, there is a race between this check and adding the publication here (video) resp here (audio)

To Reproduce

Call setMicrophoneEnabled concurrently. An over-simplified version would be

      await Future.wait([
        _room.localParticipant!.setMicrophoneEnabled(true),
        _room.localParticipant!.setMicrophoneEnabled(true)
      ]);

A workaround is of course to lock accesses to setSourceEnabled from outside the SDK, but it would be nice if the SDK could handle such cases

Expected behavior

One audio stream is published

Platform information

  • Flutter version: 3.19.5
  • Plugin version: 2.1.2
  • Flutter target OS: Android real device
  • Flutter target OS version: 13

holzgeist avatar Apr 18 '24 07:04 holzgeist

We've also seen this problem from time to time. There is a race condition in the dart code.

jezell avatar Jun 05 '24 18:06 jezell