You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2015/07/30 21:05:00 UTC

thrift git commit: THRIFT-3277 THttpClient leaks connections if it's used for multiple requests Client: Go Patch: Prashant Varanasi

Repository: thrift
Updated Branches:
  refs/heads/master 5e0f77526 -> 7505118a7


THRIFT-3277 THttpClient leaks connections if it's used for multiple requests
Client: Go
Patch: Prashant Varanasi <pr...@uber.com>

This closes #571


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7505118a
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7505118a
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7505118a

Branch: refs/heads/master
Commit: 7505118a768e7f427aee6b38ef50e7d544e75dd5
Parents: 5e0f775
Author: Jens Geyer <je...@apache.org>
Authored: Thu Jul 30 21:03:54 2015 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Thu Jul 30 21:03:54 2015 +0200

----------------------------------------------------------------------
 lib/go/thrift/http_client.go | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/7505118a/lib/go/thrift/http_client.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/http_client.go b/lib/go/thrift/http_client.go
index 0f6e704..bf0ed62 100644
--- a/lib/go/thrift/http_client.go
+++ b/lib/go/thrift/http_client.go
@@ -129,17 +129,22 @@ func (p *THttpClient) IsOpen() bool {
 	return p.response != nil || p.requestBuffer != nil
 }
 
-func (p *THttpClient) Close() error {
+func (p *THttpClient) closeResponse() error {
+	var err error
 	if p.response != nil && p.response.Body != nil {
-		err := p.response.Body.Close()
-		p.response = nil
-		return err
+		err = p.response.Body.Close()
 	}
+
+	p.response = nil
+	return err
+}
+
+func (p *THttpClient) Close() error {
 	if p.requestBuffer != nil {
 		p.requestBuffer.Reset()
 		p.requestBuffer = nil
 	}
-	return nil
+	return p.closeResponse()
 }
 
 func (p *THttpClient) Read(buf []byte) (int, error) {
@@ -171,6 +176,9 @@ func (p *THttpClient) WriteString(s string) (n int, err error) {
 }
 
 func (p *THttpClient) Flush() error {
+	// Close any previous response body to avoid leaking connections.
+	p.closeResponse()
+
 	client := &http.Client{}
 	req, err := http.NewRequest("POST", p.url.String(), p.requestBuffer)
 	if err != nil {