From 4b423838ce5af0fb2abe97c5b5773ccb5a533d71 Mon Sep 17 00:00:00 2001 From: Murtaza Aliakbar Date: Sun, 20 Oct 2024 04:44:43 +0530 Subject: [PATCH] core/connpool: exit early from infinite for-loop if pool closed --- intra/core/connpool.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/intra/core/connpool.go b/intra/core/connpool.go index 2ad60724..719e39e9 100644 --- a/intra/core/connpool.go +++ b/intra/core/connpool.go @@ -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) { @@ -242,6 +243,7 @@ func (c *ConnPool[T]) scrub() { clos(conn) } case <-c.ctx.Done(): + return default: return }