diff --git a/p2p/transport/webrtc/stream.go b/p2p/transport/webrtc/stream.go index b86128dc31..1d14875daf 100644 --- a/p2p/transport/webrtc/stream.go +++ b/p2p/transport/webrtc/stream.go @@ -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()