Skip to content

Commit 3ffc767

Browse files
committed
core/connpool: infinite scrub() loop
reads from the chan are immediately written back in to it, and so the outer unconditional for-loop spins forever as the chan never runs out of elements.
1 parent b8e8cdc commit 3ffc767

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

intra/core/connpool.go

+25-12
Original file line numberDiff line numberDiff line change
@@ -237,25 +237,38 @@ func (c *ConnPool[T]) clean() {
237237
}
238238

239239
func (c *ConnPool[T]) scrub() {
240-
for {
241-
if c.closed.Load() {
242-
return
240+
if c.closed.Load() {
241+
return
242+
}
243+
244+
staged := make([]timedconn, 0)
245+
defer func() {
246+
for _, tconn := range staged {
247+
kept := false
248+
select {
249+
case <-c.ctx.Done(): // closed
250+
default:
251+
select {
252+
case c.p <- tconn: // put it back in
253+
kept = true
254+
case <-c.ctx.Done(): // closed
255+
default: // pool full
256+
}
257+
}
258+
if !kept {
259+
CloseConn(tconn.c)
260+
}
243261
}
262+
}()
244263

264+
for {
245265
select {
246266
case tconn := <-c.p:
247267
if fresh(tconn.dob) && readable(tconn.c) {
248-
select {
249-
case c.p <- tconn: // update dob only on Put()
250-
case <-c.ctx.Done(): // stop
251-
CloseConn(tconn.c)
252-
return
253-
default: // full
254-
CloseConn(tconn.c)
255-
}
268+
staged = append(staged, tconn)
256269
} else {
257270
CloseConn(tconn.c)
258-
}
271+
} // next
259272
case <-c.ctx.Done():
260273
return
261274
default:

0 commit comments

Comments
 (0)