Skip to content

Commit

Permalink
Merge pull request #111 from Fiery-Fenix/http-keep-alive-fix
Browse files Browse the repository at this point in the history
Drain response body on exec call to enable keep-alive connection reuse
  • Loading branch information
DoubleDi committed Feb 9, 2021
2 parents e482166 + 70a1409 commit 828678e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions conn_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 828678e

Please sign in to comment.