diff --git a/backend/pool.go b/backend/pool.go index 29e130d..758e33b 100644 --- a/backend/pool.go +++ b/backend/pool.go @@ -59,7 +59,12 @@ func (cp *Pool) Get() (net.Conn, error) { } } -func (cp *Pool) Return(c net.Conn) { +func (cp *Pool) Return(c net.Conn, failed bool) { + + if failed { + <-cp.createsem + return + } select { case cp.connections <- c: default: diff --git a/backend/writer.go b/backend/writer.go index 53385ed..1d4481e 100644 --- a/backend/writer.go +++ b/backend/writer.go @@ -46,9 +46,7 @@ func (w *MetricWriter) Write(rq prompb.WriteRequest) error { bw := bufio.NewWriter(out) defer func() { bw.Flush() - if !fail { - w.pool.Return(out) - } + w.pool.Return(out, fail) }() for _, ts := range rq.Timeseries { if err := w.writeMetrics(bw, &ts); err != nil {