Skip to content

Commit

Permalink
pool: Prevent potential read goroutine leak.
Browse files Browse the repository at this point in the history
This ensures the send to the read channel for a client respects the
context since it could otherwise end up hanging forever when sending to
the channel that no longer has a goroutine reading from it thereby
leaking the goroutine.

It also includes the read goroutine in the overall waitgroup for the
client to help ensure it shuts down as intended.
  • Loading branch information
davecgh committed Sep 15, 2023
1 parent c578db9 commit b8110aa
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ func (c *Client) read() {
c.cancel()
return
}
c.readCh <- readPayload{msg, reqType}
select {
case c.readCh <- readPayload{msg, reqType}:
case <-c.ctx.Done():
c.cancel()
return
}
}
}

Expand Down Expand Up @@ -1283,10 +1288,12 @@ func (c *Client) send() {

// run handles the process lifecycles of the pool client.
func (c *Client) run() {
go c.read()

var wg sync.WaitGroup
wg.Add(4)
wg.Add(5)
go func() {
c.read()
wg.Done()
}()
go func() {
c.process()
wg.Done()
Expand Down

0 comments on commit b8110aa

Please sign in to comment.