@@ -381,21 +381,26 @@ func (p *ConnPool) popIdle() (*Conn, error) {
381
381
}
382
382
383
383
func (p * ConnPool ) Put (ctx context.Context , cn * Conn ) {
384
+ shouldRemove := false
384
385
if cn .rd .Buffered () > 0 {
385
386
// Check if this might be push notification data
386
387
if p .cfg .Protocol == 3 {
387
388
// 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
393
392
}
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
394
403
}
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
399
404
}
400
405
401
406
if ! cn .pooled {
0 commit comments