Skip to content

[bug] possible race condition in LocalParticipant.setSourceEnabled #501

@holzgeist

Description

@holzgeist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions