[MM-50751] Fix race condition attaching media tracks on join #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This was an interesting one given I could never reproduce the issue on my end, neither locally nor when connecting on remote instances.
The bug has been there for a long time as I remember first encountering this on a Community recording a few months ago. Something in the recorder setup made it more likely to reproduce. In fact, I was finally able to do this earlier today through a quick load-test on Community.
The problem was that we are registering the media track events handler(s) when mounting the component (both widget and recording view) but any delay in doing so could mean events firing before we get a chance to listen and tracks getting "lost", or better, never attached to the document, hence never played. To fix this, before listening on the track events we also check for existing available tracks and attach them accordingly.
Thanks to @hanzei for raising this issue. I was almost convinced it was a Chromium bug after the previous failed attempts at reproducing this but indeed, as often is the case, it was an issue on our end.
Ticket Link
https://mattermost.atlassian.net/browse/MM-50751