Skip to content

Commit

Permalink
Close ID pool when closing client
Browse files Browse the repository at this point in the history
For every client that `SimpleClientFactory` creates, a goroutine is started for the `idPool`.

When you call `client.Close()` the connection is closed but the `idPool` remains running.

With this change, the `idPool` is properly closed.

Co-authored-by: Adrian Philipp <adri@users.noreply.github.com>
  • Loading branch information
ruudk and adri committed Sep 15, 2020
1 parent 4371ad4 commit d0e57c7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ type idPool struct {
IDs chan uint16
}

// Close closes the IDs channel
func (p *idPool) Close() {
close(p.IDs)
}

// AllocID implements Client.AllocID
func (p *idPool) Alloc() uint16 {
return <-p.IDs
Expand Down Expand Up @@ -342,6 +347,7 @@ func (c *client) Do(req *Request) (resp *ResponsePipe, err error) {
// If the inner connection has been closed before,
// this method would do nothing and return nil
func (c *client) Close() (err error) {
c.ids.Close()
if c.conn == nil {
return
}
Expand Down

0 comments on commit d0e57c7

Please sign in to comment.