@@ -551,8 +551,8 @@ func (c *Connection) shutdown(err *Error) {
551551
552552 c .conn .Close ()
553553
554- c .channels = map [ uint16 ] * Channel {}
555- c .allocator = newAllocator ( 1 , c . Config . ChannelMax )
554+ c .channels = nil
555+ c .allocator = nil
556556 c .noNotify = true
557557 })
558558}
@@ -770,8 +770,10 @@ func (c *Connection) releaseChannel(id uint16) {
770770 c .m .Lock ()
771771 defer c .m .Unlock ()
772772
773- delete (c .channels , id )
774- c .allocator .release (int (id ))
773+ if ! c .IsClosed () {
774+ delete (c .channels , id )
775+ c .allocator .release (int (id ))
776+ }
775777}
776778
777779// openChannel allocates and opens a channel, must be paired with closeChannel
@@ -919,13 +921,17 @@ func (c *Connection) openTune(config Config, auth Authentication) error {
919921 // Edge case that may race with c.shutdown()
920922 // https://github.com/rabbitmq/amqp091-go/issues/170
921923 c .m .Lock ()
924+
922925 // When the server and client both use default 0, then the max channel is
923926 // only limited by uint16.
924927 c .Config .ChannelMax = pick (config .ChannelMax , int (tune .ChannelMax ))
925928 if c .Config .ChannelMax == 0 {
926929 c .Config .ChannelMax = defaultChannelMax
927930 }
928931 c .Config .ChannelMax = min (c .Config .ChannelMax , maxChannelMax )
932+
933+ c .allocator = newAllocator (1 , c .Config .ChannelMax )
934+
929935 c .m .Unlock ()
930936
931937 // Frame size includes headers and end byte (len(payload)+8), even if
@@ -982,9 +988,6 @@ func (c *Connection) openComplete() error {
982988 _ = deadliner .SetDeadline (time.Time {})
983989 }
984990
985- c .m .Lock ()
986- c .allocator = newAllocator (1 , c .Config .ChannelMax )
987- c .m .Unlock ()
988991 return nil
989992}
990993
0 commit comments