Skip to content

Commit 534c83a

Browse files
committed
what if those conns are tracked and closed on Close?
1 parent b80f6d5 commit 534c83a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

internal/pool/pool.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ type Pooler interface {
6868
AddPoolHook(hook PoolHook)
6969
RemovePoolHook(hook PoolHook)
7070

71+
TrackConn(*Conn)
72+
UntrackConn(*Conn)
73+
7174
Close() error
7275
}
7376

@@ -736,3 +739,20 @@ func (p *ConnPool) isHealthyConn(cn *Conn, now time.Time) bool {
736739
}
737740
return true
738741
}
742+
743+
func (p *ConnPool) TrackConn(cn *Conn) {
744+
p.connsMu.Lock()
745+
p.conns = append(p.conns, cn)
746+
p.connsMu.Unlock()
747+
}
748+
749+
func (p *ConnPool) UntrackConn(cn *Conn) {
750+
p.connsMu.Lock()
751+
for i, c := range p.conns {
752+
if c == cn {
753+
p.conns = append(p.conns[:i], p.conns[i+1:]...)
754+
break
755+
}
756+
}
757+
p.connsMu.Unlock()
758+
}

redis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,12 @@ func (c *Client) pubSub() *PubSub {
10711071
return nil, err
10721072
}
10731073

1074+
c.pool.TrackConn(cn)
10741075
return cn, nil
10751076
},
10761077
closeConn: func(cn *pool.Conn) error {
10771078
_ = cn.Close()
1079+
c.pool.UntrackConn(cn)
10781080
return nil
10791081
},
10801082
pushProcessor: c.pushProcessor,

0 commit comments

Comments
 (0)