pion / mediadevices

Go implementation of the MediaDevices API.
https://pion.ly/
MIT License
521 stars 120 forks source link

Fix deadlock in track.Bind() #466

Closed KW-M closed 1 year ago

KW-M commented 1 year ago

Description

Occurs when read errors happen from a driver source during a call to track.Bind()

Example of deadlock:

  1. When a driver reader function has a read error immediately after being initialized: contrived example:

    video.ReaderFunc(func() (image.Image, func(), error) {
    return nil, nil, errors.New("Ahhhh")
    })
  2. Pion calls bind() on a track using that reader function.

  3. Within NewRTPReader(): a. The reader function is wrapped to call track.onError if a read error is returned in newVideoTrackFromReader() b. Read is called synchronously in detectCurrentVideoProp() in the function newEncodedReader() c. track.onError() is triggered within the bind function (so without this fix, the mutex lock on bind() will not yet be released, and would deadlock in track.onError())

codecov[bot] commented 1 year ago

Codecov Report

Base: 58.21% // Head: 58.08% // Decreases project coverage by -0.13% :warning:

Coverage data is based on head (d67a730) compared to base (f8f8511). Patch coverage: 33.33% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #466 +/- ## ========================================== - Coverage 58.21% 58.08% -0.13% ========================================== Files 62 62 Lines 3683 3691 +8 ========================================== Hits 2144 2144 - Misses 1412 1420 +8 Partials 127 127 ``` | [Impacted Files](https://codecov.io/gh/pion/mediadevices/pull/466?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | | |---|---|---| | [track.go](https://codecov.io/gh/pion/mediadevices/pull/466?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-dHJhY2suZ28=) | `24.69% <33.33%> (-0.63%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.