diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 4cdcff2..ff94642 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -310,6 +310,12 @@ func (p *ConnPool) popIdle() *Conn { } func (p *ConnPool) Put(cn *Conn) { + if cn.rd.Buffered() > 0 { + internal.Logger.Printf("Conn has unread data") + p.Remove(cn, BadConnError{}) + return + } + if !cn.pooled { p.Remove(cn, nil) return diff --git a/internal/proto/reader.go b/internal/proto/reader.go index 7a2777e..a48f1ae 100644 --- a/internal/proto/reader.go +++ b/internal/proto/reader.go @@ -41,6 +41,10 @@ func NewReader(rd io.Reader) *Reader { } } +func (r *Reader) Buffered() int { + return r.rd.Buffered() +} + func (r *Reader) Reset(rd io.Reader) { r.rd.Reset(rd) }