Skip to content

Commit 1d204c2

Browse files
committed
fix(pool): return connection in the pool
1 parent 8418c6b commit 1d204c2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

internal/pool/pool.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,26 @@ func (p *ConnPool) popIdle() (*Conn, error) {
381381
}
382382

383383
func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
384+
shouldRemove := false
384385
if cn.rd.Buffered() > 0 {
385386
// Check if this might be push notification data
386387
if p.cfg.Protocol == 3 {
387388
// we know that there is something in the buffer, so peek at the next reply type without
388-
// the potential to block
389-
if replyType, err := cn.rd.PeekReplyType(); err == nil && replyType == proto.RespPush {
390-
// For push notifications, we allow some buffered data
391-
// The client will process these notifications before using the connection
392-
return
389+
// the potential to block and check if it's a push notification
390+
if replyType, err := cn.rd.PeekReplyType(); err != nil || replyType != proto.RespPush {
391+
shouldRemove = true
393392
}
393+
} else {
394+
// not a push notification since protocol 2 doesn't support them
395+
shouldRemove = true
396+
}
397+
398+
if shouldRemove {
399+
// For non-RESP3 or data that is not a push notification, buffered data is unexpected
400+
internal.Logger.Printf(ctx, "Conn has unread data, closing it")
401+
p.Remove(ctx, cn, BadConnError{})
402+
return
394403
}
395-
// For non-RESP3 or data that is not a push notification, buffered data is unexpected
396-
internal.Logger.Printf(ctx, "Conn has unread data, closing it")
397-
p.Remove(ctx, cn, BadConnError{})
398-
return
399404
}
400405

401406
if !cn.pooled {

0 commit comments

Comments
 (0)