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

@ -57,6 +57,13 @@ var _ = Describe("Streams Map", func() {
Expect(err).To(MatchError("InvalidStreamID: attempted to open stream 6 from client-side"))
})
It("rejects streams with even IDs, which are lower thatn the highest client-side stream", func() {
_, err := m.GetOrOpenStream(5)
Expect(err).NotTo(HaveOccurred())
_, err = m.GetOrOpenStream(4)
Expect(err).To(MatchError("InvalidStreamID: attempted to open stream 4 from client-side"))
})
It("gets existing streams", func() {
s, err := m.GetOrOpenStream(5)
Expect(err).NotTo(HaveOccurred())
@ -137,6 +144,17 @@ var _ = Describe("Streams Map", func() {
Expect(err).To(MatchError(testErr))
})
It("doesn't reopen an already closed stream", func() {
str, err := m.OpenStream()
Expect(err).ToNot(HaveOccurred())
Expect(str.StreamID()).To(Equal(protocol.StreamID(2)))
err = m.RemoveStream(2)
Expect(err).ToNot(HaveOccurred())
str, err = m.GetOrOpenStream(2)
Expect(err).ToNot(HaveOccurred())
Expect(str).To(BeNil())
})
Context("counting streams", func() {
It("errors when too many streams are opened", func() {
for i := 1; i <= maxOutgoingStreams; i++ {
@ -353,12 +371,19 @@ var _ = Describe("Streams Map", func() {
setNewStreamsMap(protocol.PerspectiveClient)
})
Context("client-side streams, as a client", func() {
Context("client-side streams", func() {
It("rejects streams with odd IDs", func() {
_, err := m.GetOrOpenStream(5)
Expect(err).To(MatchError("InvalidStreamID: attempted to open stream 5 from server-side"))
})
It("rejects streams with odds IDs, which are lower thatn the highest server-side stream", func() {
_, err := m.GetOrOpenStream(6)
Expect(err).NotTo(HaveOccurred())
_, err = m.GetOrOpenStream(5)
Expect(err).To(MatchError("InvalidStreamID: attempted to open stream 5 from server-side"))
})
It("gets new streams", func() {
s, err := m.GetOrOpenStream(2)
Expect(err).NotTo(HaveOccurred())
@ -374,6 +399,17 @@ var _ = Describe("Streams Map", func() {
Expect(m.streams).To(HaveKey(protocol.StreamID(4)))
Expect(m.streams).To(HaveKey(protocol.StreamID(6)))
})
It("doesn't reopen an already closed stream", func() {
str, err := m.OpenStream()
Expect(err).ToNot(HaveOccurred())
Expect(str.StreamID()).To(Equal(protocol.StreamID(1)))
err = m.RemoveStream(1)
Expect(err).ToNot(HaveOccurred())
str, err = m.GetOrOpenStream(1)
Expect(err).ToNot(HaveOccurred())
Expect(str).To(BeNil())
})
})
Context("server-side streams", func() {
@ -393,6 +429,16 @@ var _ = Describe("Streams Map", func() {
Expect(err).ToNot(HaveOccurred())
Expect(s2.StreamID()).To(Equal(s1.StreamID() + 2))
})
It("doesn't reopen an already closed stream", func() {
_, err := m.GetOrOpenStream(4)
Expect(err).ToNot(HaveOccurred())
err = m.RemoveStream(4)
Expect(err).ToNot(HaveOccurred())
str, err := m.GetOrOpenStream(4)
Expect(err).ToNot(HaveOccurred())
Expect(str).To(BeNil())
})
})
Context("accepting streams", func() {