From 5327164bf179a08c8751b9693606fa73d608b833 Mon Sep 17 00:00:00 2001 From: Vyacheslav Stepanov Date: Thu, 4 Feb 2021 17:40:31 +0200 Subject: [PATCH 1/2] Drain response body on exec call to enable keep-alive connection reuse --- conn.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conn.go b/conn.go index 62bd12d..6c59406 100644 --- a/conn.go +++ b/conn.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "log" "net" "net/http" @@ -211,6 +212,8 @@ func (c *conn) killQuery(req *http.Request, args []driver.Value) error { return err } if body != nil { + // Drain body to enable connection reuse + io.Copy(ioutil.Discard, body) body.Close() } return nil @@ -248,6 +251,8 @@ func (c *conn) exec(ctx context.Context, query string, args []driver.Value) (dri } body, err := c.doRequest(ctx, req) if body != nil { + // Drain body to enable connection reuse + io.Copy(ioutil.Discard, body) body.Close() } return emptyResult, err From 70a14094e5351e664fd839ebf6696ae85ab4b773 Mon Sep 17 00:00:00 2001 From: Vyacheslav Stepanov Date: Mon, 8 Feb 2021 16:05:11 +0200 Subject: [PATCH 2/2] Added response body close for "ping" request --- conn_go18.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conn_go18.go b/conn_go18.go index 5fec71f..5b8cdc9 100644 --- a/conn_go18.go +++ b/conn_go18.go @@ -29,6 +29,8 @@ func (c *conn) Ping(ctx context.Context) error { if err != nil { return err } + // Close response body to enable connection reuse + defer respBody.Close() resp, err := ioutil.ReadAll(respBody) if err != nil { return err