@@ -381,21 +381,26 @@ func (p *ConnPool) popIdle() (*Conn, error) {
381381}
382382
383383func (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