error when receiving stream data with a larger offset than the final offset

This could happen when a peer send a STREAM frame with the Fin bit set,
and then sends STREAM frames with a higher offset.
This commit is contained in:
Marten Seemann
2017-10-25 10:43:29 +07:00
parent 816cf90ea7
commit 636bf4578c
2 changed files with 24 additions and 3 deletions

View File

@@ -12,10 +12,12 @@ import (
type streamFlowController struct {
baseFlowController
connection connectionFlowControllerI
streamID protocol.StreamID
streamID protocol.StreamID
connection connectionFlowControllerI
contributesToConnection bool // does the stream contribute to connection level flow control
receivedFinalOffset bool
}
var _ StreamFlowController = &streamFlowController{}
@@ -50,7 +52,12 @@ func (c *streamFlowController) UpdateHighestReceived(byteOffset protocol.ByteCou
c.mutex.Lock()
defer c.mutex.Unlock()
// TODO(#382): check for StreamDataAfterTermination errors, when receiving an offset after we already received a final offset
if c.receivedFinalOffset && byteOffset > c.highestReceived {
return qerr.StreamDataAfterTermination
}
if final {
c.receivedFinalOffset = true
}
if byteOffset == c.highestReceived {
return nil
}

View File

@@ -110,6 +110,20 @@ var _ = Describe("Stream Flow controller", func() {
err := controller.UpdateHighestReceived(99, true)
Expect(err).To(MatchError(qerr.StreamDataAfterTermination))
})
It("accepts delayed data after receiving a final offset", func() {
err := controller.UpdateHighestReceived(300, true)
Expect(err).ToNot(HaveOccurred())
err = controller.UpdateHighestReceived(250, false)
Expect(err).ToNot(HaveOccurred())
})
It("errors when receiving a higher offset after receiving a final offset", func() {
err := controller.UpdateHighestReceived(200, true)
Expect(err).ToNot(HaveOccurred())
err = controller.UpdateHighestReceived(250, false)
Expect(err).To(MatchError(qerr.StreamDataAfterTermination))
})
})
Context("registering data read", func() {