Skip to content

Commit

Permalink
webrtc: set buffer amount to 0 when closing stream
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 30, 2023
1 parent 2f62254 commit 7989608
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions p2p/transport/webrtc/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ func (s *stream) maybeDeclareStreamDone() {
(s.receiveState == receiveStateReset || s.receiveState == receiveStateDataRead) &&
len(s.controlMsgQueue) == 0 {
_ = s.SetReadDeadline(time.Now().Add(-1 * time.Hour)) // pion ignores zero times
// TODO: it's not clear if this is actually a fix or just a workaround.
// What happens if this message is lost?
// See https://github.com/libp2p/go-libp2p/pull/2337#issuecomment-1696619731.
s.dataChannel.SetBufferedAmountLowThreshold(0)
ch := make(chan struct{})
s.dataChannel.OnBufferedAmountLow(func() { ch <- struct{}{} })
<-ch
_ = s.dataChannel.Close()
// TODO: write for the spawned reader to return
s.onDone()
Expand Down

0 comments on commit 7989608

Please sign in to comment.