flowcontrol: fix start of the flow-control auto-tuning period (#4730)

The period should start when the first frame is received, not when the data is
first read. This makes a difference when the first STREAM frame is received
out of order.
This commit is contained in:
Marten Seemann
2024-11-28 15:48:42 +08:00
committed by GitHub
parent ca31dd355c
commit 90a824a849
3 changed files with 12 additions and 7 deletions

View File

@@ -66,11 +66,6 @@ func (c *baseFlowController) sendWindowSize() protocol.ByteCount {
// needs to be called with locked mutex
func (c *baseFlowController) addBytesRead(n protocol.ByteCount) {
// pretend we sent a WindowUpdate when reading the first byte
// this way auto-tuning of the window size already works for the first WindowUpdate
if c.bytesRead == 0 {
c.startNewAutoTuningEpoch(time.Now())
}
c.bytesRead += n
}

View File

@@ -46,7 +46,12 @@ func (c *connectionFlowController) IncrementHighestReceived(increment protocol.B
c.mutex.Lock()
defer c.mutex.Unlock()
// If this is the first frame received on this connection, start flow-control auto-tuning.
if c.highestReceived == 0 {
c.startNewAutoTuningEpoch(time.Now())
}
c.highestReceived += increment
if c.checkFlowControlViolation() {
return &qerr.TransportError{
ErrorCode: qerr.FlowControlError,

View File

@@ -2,6 +2,7 @@ package flowcontrol
import (
"fmt"
"time"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/qerr"
@@ -70,8 +71,7 @@ func (c *streamFlowController) UpdateHighestReceived(offset protocol.ByteCount,
if offset == c.highestReceived {
return nil
}
// A higher offset was received before.
// This can happen due to reordering.
// A higher offset was received before. This can happen due to reordering.
if offset <= c.highestReceived {
if final {
return &qerr.TransportError{
@@ -82,8 +82,13 @@ func (c *streamFlowController) UpdateHighestReceived(offset protocol.ByteCount,
return nil
}
// If this is the first frame received for this stream, start flow-control auto-tuning.
if c.highestReceived == 0 {
c.startNewAutoTuningEpoch(time.Now())
}
increment := offset - c.highestReceived
c.highestReceived = offset
if c.checkFlowControlViolation() {
return &qerr.TransportError{
ErrorCode: qerr.FlowControlError,