Disable data channel throttle by default (#3281)

* Disable data channel throttle by default

* data race

* err type
This commit is contained in:
cnderrauber
2024-12-21 12:08:54 +08:00
committed by GitHub
parent 92ae45cf07
commit 8fa1127724
6 changed files with 44 additions and 34 deletions
+7 -2
View File
@@ -3,6 +3,7 @@ package datachannel
import (
"context"
"errors"
"fmt"
"time"
"github.com/pion/datachannel"
@@ -62,8 +63,12 @@ func (w *DataChannelWriter[T]) Write(p []byte) (n int, err error) {
now := mono.Now()
w.rate.AddBytes(n, int(w.bufferGetter.BufferedAmount()), now)
// retry if the write timed out on a non-slow receiver
if errors.Is(err, context.DeadlineExceeded) && w.rate.Bitrate(now) > w.slowThreshold {
continue
if errors.Is(err, context.DeadlineExceeded) {
if bitrate := w.rate.Bitrate(now); bitrate >= w.slowThreshold {
continue
} else {
err = fmt.Errorf("%w: bitrate %d, threshold %d", ErrDataDroppedBySlowReader, bitrate, w.slowThreshold)
}
}
return
@@ -32,7 +32,7 @@ func TestDataChannelWriter(t *testing.T) {
// bitrate below slow threshold(2000bytes/3sec), should drop by timeout
mockDC.SetNextWriteCompleteAt(t0.Add(3 * time.Second))
n, err = w.Write(buf[:1000])
require.ErrorIs(t, err, context.DeadlineExceeded, err)
require.ErrorIs(t, err, ErrDataDroppedBySlowReader, err)
require.Equal(t, 0, n)
}