ensure session is closed when TooManyStreams occurs

This commit is contained in:
Lucas Clemente
2016-06-06 22:03:31 +02:00
parent 531fc718b5
commit 6cc5440240
2 changed files with 5 additions and 2 deletions

View File

@@ -610,6 +610,7 @@ func (s *Session) GetOrOpenStream(id protocol.StreamID) (utils.Stream, error) {
func (s *Session) newStreamImpl(id protocol.StreamID) (*stream, error) {
maxAllowedStreams := uint32(protocol.MaxStreamsMultiplier * float32(s.connectionParametersManager.GetMaxStreamsPerConnection()))
if atomic.LoadUint32(&s.openStreamsCount) >= maxAllowedStreams {
go s.Close(qerr.TooManyOpenStreams)
return nil, qerr.TooManyOpenStreams
}
if _, ok := s.streams[id]; ok {

View File

@@ -682,14 +682,16 @@ var _ = Describe("Session", 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
for i := 2; i <= 110; i++ {
_, err := session.OpenStream(protocol.StreamID(i))
Expect(err).NotTo(HaveOccurred())
}
_, err := session.OpenStream(protocol.StreamID(110))
_, err := session.OpenStream(protocol.StreamID(111))
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() {