From f51cfe9fe3f87d88f3deb121e5e03c0dba3cda86 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 6 Dec 2017 20:25:37 +0700 Subject: [PATCH] don't send a window update after the final offset was received Receiving a final offset means the peer is done sending on that stream, and there's no need to grant additional flow control credit. --- internal/flowcontrol/stream_flow_controller.go | 5 +++++ internal/flowcontrol/stream_flow_controller_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/internal/flowcontrol/stream_flow_controller.go b/internal/flowcontrol/stream_flow_controller.go index 96e13dc3b..dadba72e5 100644 --- a/internal/flowcontrol/stream_flow_controller.go +++ b/internal/flowcontrol/stream_flow_controller.go @@ -116,6 +116,11 @@ func (c *streamFlowController) GetWindowUpdate() protocol.ByteCount { c.mutex.Lock() defer c.mutex.Unlock() + // if we already received the final offset for this stream, the peer won't need any additional flow control credit + if c.receivedFinalOffset { + return 0 + } + oldWindowIncrement := c.receiveWindowIncrement offset := c.baseFlowController.getWindowUpdate() if c.receiveWindowIncrement > oldWindowIncrement { // auto-tuning enlarged the window increment diff --git a/internal/flowcontrol/stream_flow_controller_test.go b/internal/flowcontrol/stream_flow_controller_test.go index 0718c6a06..76c1e9dfb 100644 --- a/internal/flowcontrol/stream_flow_controller_test.go +++ b/internal/flowcontrol/stream_flow_controller_test.go @@ -193,6 +193,14 @@ var _ = Describe("Stream Flow controller", func() { Expect(controller.receiveWindowIncrement).To(Equal(2 * oldIncrement)) Expect(controller.connection.(*connectionFlowController).receiveWindowIncrement).To(Equal(protocol.ByteCount(120))) // unchanged }) + + It("doesn't increase the window after a final offset was already received", func() { + controller.AddBytesRead(80) + err := controller.UpdateHighestReceived(90, true) + Expect(err).ToNot(HaveOccurred()) + offset := controller.GetWindowUpdate() + Expect(offset).To(BeZero()) + }) }) })