Don't drop message if calculate duration is too small (#3442)

* Don't drop message if calculate duration is too small

* fix test
This commit is contained in:
cnderrauber
2025-02-18 14:41:41 +08:00
committed by GitHub
parent b3da3ff2cb
commit b2a54729f5
6 changed files with 23 additions and 11 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func (w *DataChannelWriter[T]) Write(p []byte) (n int, err error) {
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) {
if bitrate := w.rate.Bitrate(now); bitrate >= w.slowThreshold {
if bitrate, ok := w.rate.Bitrate(now); !ok || bitrate >= w.slowThreshold {
continue
} else {
err = fmt.Errorf("%w: bitrate %d, threshold %d", ErrDataDroppedBySlowReader, bitrate, w.slowThreshold)