forked from quic-go/quic-go
ensure session is closed when TooManyStreams occurs
This commit is contained in:
@@ -610,6 +610,7 @@ func (s *Session) GetOrOpenStream(id protocol.StreamID) (utils.Stream, error) {
|
|||||||
func (s *Session) newStreamImpl(id protocol.StreamID) (*stream, error) {
|
func (s *Session) newStreamImpl(id protocol.StreamID) (*stream, error) {
|
||||||
maxAllowedStreams := uint32(protocol.MaxStreamsMultiplier * float32(s.connectionParametersManager.GetMaxStreamsPerConnection()))
|
maxAllowedStreams := uint32(protocol.MaxStreamsMultiplier * float32(s.connectionParametersManager.GetMaxStreamsPerConnection()))
|
||||||
if atomic.LoadUint32(&s.openStreamsCount) >= maxAllowedStreams {
|
if atomic.LoadUint32(&s.openStreamsCount) >= maxAllowedStreams {
|
||||||
|
go s.Close(qerr.TooManyOpenStreams)
|
||||||
return nil, qerr.TooManyOpenStreams
|
return nil, qerr.TooManyOpenStreams
|
||||||
}
|
}
|
||||||
if _, ok := s.streams[id]; ok {
|
if _, ok := s.streams[id]; ok {
|
||||||
|
|||||||
@@ -682,14 +682,16 @@ var _ = Describe("Session", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Context("counting streams", func() {
|
Context("counting streams", func() {
|
||||||
It("errors when too many streams are opened", func() {
|
It("errors when too many streams are opened", func(done Done) {
|
||||||
// 1.1 * 100
|
// 1.1 * 100
|
||||||
for i := 2; i <= 110; i++ {
|
for i := 2; i <= 110; i++ {
|
||||||
_, err := session.OpenStream(protocol.StreamID(i))
|
_, err := session.OpenStream(protocol.StreamID(i))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
_, err := session.OpenStream(protocol.StreamID(110))
|
_, err := session.OpenStream(protocol.StreamID(111))
|
||||||
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
|
||||||
|
Eventually(session.closeChan).Should(Receive())
|
||||||
|
close(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("does not error when many streams are opened and closed", func() {
|
It("does not error when many streams are opened and closed", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user