Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataChannel negotiated peer connection's server.AddTrack doesn't always trigger client.OnTrack #2774

Closed
nicksanford opened this issue May 28, 2024 · 7 comments · Fixed by #2786

Comments

@nicksanford
Copy link

nicksanford commented May 28, 2024

NOTE: This is my first issue/contribution to Pion. I've done my best to follow the contribution guidelines but if I've missed the mark please let me know.

Your environment.

  • 2 webrtc peers using pion/webrtc/v3.2.40

What did you do?

  1. Established a PeerConnection negotiated over a data channel between a client (recvonly) and a server (sendonly)
  2. Once pc.OnOpen is called on both the client & server, the server creates a NewTrackLocalStaticSample sending h264, passes it to pc.AddTrack, and starts calling trackLocal.WriteSample
  3. Client waits for pc.OnTrack to be invoked so it can start receiving the RTP packets written by server

Repro test case: #2775

What did you expect?

The Client's pc.OnTrack callback function is always invoked

What happened?

Sometimes the client's pc.OnTrack callback function is not invoked

Additional Notes:

I think the problem might be in peerconnection.go 's onNegotiationNeeded state machine which changes states even if the onNegotiationNeededHandler is not installed. If I uncomment these lines the repro test case doesn't fail.

@streamer45
Copy link
Contributor

@nicksanford @Sean-Der These changes (pulled from v3.2.42) are causing a regression on our end. A pion-based client is, at times, triggering step 2.2 and ending up in an endless loop.

webrtc/peerconnection.go

Lines 330 to 334 in 43a6a69

// non-canon step 2.2
if !pc.ops.IsEmpty() {
pc.ops.Enqueue(pc.negotiationNeededOp)
return
}

I am trying to assemble a simple reproducer but let me know if you have any thoughts.

@edaniels
Copy link
Member

@nicksanford @Sean-Der These changes (pulled from v3.2.42) are causing a regression on our end. A pion-based client is, at times, triggering step 2.2 and ending up in an endless loop.

webrtc/peerconnection.go

Lines 330 to 334 in 43a6a69

// non-canon step 2.2
if !pc.ops.IsEmpty() {
pc.ops.Enqueue(pc.negotiationNeededOp)
return
}

I am trying to assemble a simple reproducer but let me know if you have any thoughts.

Taking a look now

@edaniels
Copy link
Member

So it turns out my patch was partially wrong and this issue is a non-issue. Firing the event handler again after negotiation is already needed is not allowed. This means @nicksanford that if you want to see a negotiation needed event, you must set the handler prior to any background operations happening that could cause the event to fire.

@edaniels
Copy link
Member

@streamer45 published https://github.com/pion/webrtc/releases/tag/v3.2.43. let me know if you see the same issue.

@streamer45
Copy link
Contributor

Thanks @edaniels for the incredibly quick turnaround on this! The new changes are working as expected.

@edaniels
Copy link
Member

Great! No problem, sorry for the regression!

@streamer45
Copy link
Contributor

No worries. This simply made a bunch of e2e tests fail on our CI, so it was caught pretty early in the process.

@edaniels edaniels closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants