fix stream id checks in streamsMap

There were several bugs here:
- We must always return an error when the peer tries to open a stream
from the wrong side.
- We must never return an error when GetOrOpenStream is called for a
stream that was already closed. GetOrOpenStream is called when a frame
on a stream is received, so this happens when we receive retransmissions
of STREAM frames for a closed stream. We only used to do that check for
peer-initiated streams, not for streams we opened ourselves.
This commit is contained in:
Marten Seemann 2017-06-22 09:24:31 +02:00
parent 1106fbf5a1
commit f333a9b3e7
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
3 changed files with 97 additions and 13 deletions

View file

@ -394,10 +394,9 @@ var _ = Describe("Session", func() {
Expect(err).ToNot(HaveOccurred())
})
It("ignores streams that existed previously", func() {
It("ignores STREAM frames for closed streams (client-side)", func() {
sess.handleStreamFrame(&frames.StreamFrame{
StreamID: 5,
Data: []byte{},
FinBit: true,
})
str, _ := sess.streamsMap.GetOrOpenStream(5)
@ -407,11 +406,38 @@ var _ = Describe("Session", func() {
str.Close()
str.sentFin()
sess.garbageCollectStreams()
str, _ = sess.streamsMap.GetOrOpenStream(5)
Expect(str).To(BeNil()) // make sure the stream is gone
err = sess.handleStreamFrame(&frames.StreamFrame{
StreamID: 5,
Data: []byte{},
Data: []byte("foobar"),
})
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
})
It("ignores STREAM frames for closed streams (server-side)", func() {
ostr, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
Expect(ostr.StreamID()).To(Equal(protocol.StreamID(2)))
err = sess.handleStreamFrame(&frames.StreamFrame{
StreamID: 2,
FinBit: true,
})
Expect(err).ToNot(HaveOccurred())
str, _ := sess.streamsMap.GetOrOpenStream(2)
Expect(str).ToNot(BeNil())
_, err = str.Read([]byte{0})
Expect(err).To(MatchError(io.EOF))
str.Close()
str.sentFin()
sess.garbageCollectStreams()
str, _ = sess.streamsMap.GetOrOpenStream(2)
Expect(str).To(BeNil()) // make sure the stream is gone
err = sess.handleStreamFrame(&frames.StreamFrame{
StreamID: 2,
FinBit: true,
})
Expect(err).ToNot(HaveOccurred())
})
})