How do you deal with mediasoup race condition

Hi, I was looking for similar question on forum but I didn’t find any. Which is odd for me because if I understand correctly this should be pretty popular problem(but maybe I don’t understand how exactly mediasoup works).

So positive situation: someone joins to our room and he starts producing, info about this is send to backend and backend informs other users so they can consume.

But if someone joins and leaves very quickly or if user which will consume has poor internet connection. I can totally imagine situation where user firstly get info about closing consumer, but this consumer didn’t started yet.

What is more by mistake I implemented un/mute option as create/close producent so I can easily test situation when someone quickly “join” and “disconnect” and this race condition totally happens. So what is typical way of addressing this problem.

I don’t understand how would you know about consumer closing before you know it exists though

This is an async world and your app needs to check status of things after async actions complete. Always.

If you talk about JavaScript client or server application, there is actually no race conditions. Although functions are executed asynchronously on the single JS thread, any state is deterministic, you don’t need critical sections to check and change it.