From 980d0e398f22efba39d0db57daa2fa53de85d42e Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 9 Jan 2017 10:15:12 +0700 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20add=20bytes=20read=20after=20re?= =?UTF-8?q?ceiving=20a=20RST=5FSTREAM=20to=20flow=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stream.go | 5 ++++- stream_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/stream.go b/stream.go index 0c4a8accb..72d3ec87c 100644 --- a/stream.go +++ b/stream.go @@ -120,7 +120,10 @@ func (s *stream) Read(p []byte) (int, error) { bytesRead += m s.readOffset += protocol.ByteCount(m) - s.flowControlManager.AddBytesRead(s.streamID, protocol.ByteCount(m)) + // when a RST_STREAM was received, the was already informed about the final byteOffset for this stream + if !s.resetRemotely.Get() { + s.flowControlManager.AddBytesRead(s.streamID, protocol.ByteCount(m)) + } s.onData() // so that a possible WINDOW_UPDATE is sent if s.readPosInFrame >= int(frame.DataLen()) { diff --git a/stream_test.go b/stream_test.go index 0d5dfd498..9a3265f5d 100644 --- a/stream_test.go +++ b/stream_test.go @@ -64,6 +64,7 @@ func (m *mockFlowControlHandler) AddBytesRead(streamID protocol.StreamID, n prot } func (m *mockFlowControlHandler) ResetStream(streamID protocol.StreamID, byteOffset protocol.ByteCount) error { + m.bytesRead = byteOffset return m.UpdateHighestReceived(streamID, byteOffset) } @@ -494,6 +495,22 @@ var _ = Describe("Stream", func() { Expect(n).To(Equal(1)) }) + It("doesn't inform the flow controller about bytes read after receiving the remote error", func() { + str.flowControlManager = newMockFlowControlHandler() + frame := frames.StreamFrame{ + Offset: 0, + StreamID: 5, + Data: []byte{0xDE, 0xAD, 0xBE, 0xEF}, + } + str.AddStreamFrame(&frame) + str.flowControlManager.ResetStream(5, 4) + str.RegisterRemoteError(testErr) + b := make([]byte, 3) + _, err := str.Read(b) + Expect(err).ToNot(HaveOccurred()) + Expect(str.flowControlManager.(*mockFlowControlHandler).bytesRead).To(BeEquivalentTo(4)) + }) + It("stops writing after receiving a remote error", func() { var writeReturned bool var n int