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 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