ionorg / ion-sfu

Pure Go WebRTC SFU
MIT License
980 stars 238 forks source link

Not all relayed tracks received due to race condition #673

Open fffilimonov opened 1 year ago

fffilimonov commented 1 year ago

Your environment.

What did you do?

Trying to relay tracks between 2 ion-sfu

What did you expect?

Tracks relayed

What happened?

I do:

Peer.Publisher().Relay(...)
session.AddRelayPeer(peerID string, signalData []byte) ([]byte, error)

sometimes first relayed track from SFU1 not received on SFU2

I found the root cause: SFU1 call createRelayTrack after OnOpen event for dataChannel created between SFU1 and SFU2
it leads to sending message via dataChannel to SFU2 with ion_relay_request for this track
sometimes SFU2 receives message ion_relay_request from dataChannel before OnOpen fired on SFU2 and NewRelayPeer called it leads to calling receive with no onTrack handlers set

As I understand OnOpen for dataChannel on SFU1 side and OnOpen on SFU2 not synchronized.