From 4d3ed95bd9d4e1f750ee30b9f5b0dbc2ab71db13 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Fri, 9 Aug 2019 15:11:52 +0300 Subject: [PATCH] Add conn health check --- internal/pool/pool.go | 6 ++++++ internal/proto/reader.go | 4 ++++ 2 files changed, 10 insertions(+) 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) }