Skip to content

Commit

Permalink
core/connpool: exit early from infinite for-loop if pool closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Oct 19, 2024
1 parent 9539876 commit 4b42383
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions intra/core/connpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ func (c *ConnPool[T]) clean() {
}

func (c *ConnPool[T]) scrub() {
if c.closed.Load() {
return
}
for {
if c.closed.Load() {
return
}

select {
case conn := <-c.p:
if readable(conn) {
Expand All @@ -242,6 +243,7 @@ func (c *ConnPool[T]) scrub() {
clos(conn)
}
case <-c.ctx.Done():
return
default:
return
}
Expand Down

1 comment on commit 4b42383

@ignoramous
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.