Skip to content

Commit

Permalink
Set channels and allocator to nil in shutdown
Browse files Browse the repository at this point in the history
Follow up to #171

cc @Zerpet
  • Loading branch information
lukebakken committed Feb 8, 2023
1 parent 7b4cb59 commit 2d55559
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ func (c *Connection) shutdown(err *Error) {

c.conn.Close()

c.channels = map[uint16]*Channel{}
c.allocator = newAllocator(1, c.Config.ChannelMax)
c.channels = nil
c.allocator = nil
c.noNotify = true
})
}
Expand Down Expand Up @@ -766,8 +766,10 @@ func (c *Connection) releaseChannel(id uint16) {
c.m.Lock()
defer c.m.Unlock()

delete(c.channels, id)
c.allocator.release(int(id))
if !c.IsClosed() {
delete(c.channels, id)
c.allocator.release(int(id))
}
}

// openChannel allocates and opens a channel, must be paired with closeChannel
Expand Down Expand Up @@ -915,13 +917,17 @@ func (c *Connection) openTune(config Config, auth Authentication) error {
// Edge case that may race with c.shutdown()
// https://github.com/rabbitmq/amqp091-go/issues/170
c.m.Lock()

// When the server and client both use default 0, then the max channel is
// only limited by uint16.
c.Config.ChannelMax = pick(config.ChannelMax, int(tune.ChannelMax))
if c.Config.ChannelMax == 0 {
c.Config.ChannelMax = defaultChannelMax
}
c.Config.ChannelMax = min(c.Config.ChannelMax, maxChannelMax)

c.allocator = newAllocator(1, c.Config.ChannelMax)

c.m.Unlock()

// Frame size includes headers and end byte (len(payload)+8), even if
Expand Down Expand Up @@ -978,9 +984,6 @@ func (c *Connection) openComplete() error {
_ = deadliner.SetDeadline(time.Time{})
}

c.m.Lock()
c.allocator = newAllocator(1, c.Config.ChannelMax)
c.m.Unlock()
return nil
}

Expand Down

0 comments on commit 2d55559

Please sign in to comment.