You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by yu...@apache.org on 2022/02/04 00:11:28 UTC

[thrift] branch master updated: THRIFT-5509: Close connection in IsOpen

This is an automated email from the ASF dual-hosted git repository.

yuxuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 6f33b04  THRIFT-5509: Close connection in IsOpen
6f33b04 is described below

commit 6f33b047067966d73397b95e6a54fc39901169eb
Author: Yuxuan 'fishy' Wang <yu...@reddit.com>
AuthorDate: Thu Feb 3 10:44:53 2022 -0800

    THRIFT-5509: Close connection in IsOpen
    
    Client: go
    
    When the connectivity check failed in IsOpen, close the connection
    explicitly to avoid connection leaks.
    
    This is Path 2 of THRIFT-5509.
---
 lib/go/thrift/socket_conn.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/go/thrift/socket_conn.go b/lib/go/thrift/socket_conn.go
index 5619d96..bbb5b7d 100644
--- a/lib/go/thrift/socket_conn.go
+++ b/lib/go/thrift/socket_conn.go
@@ -20,6 +20,7 @@
 package thrift
 
 import (
+	"errors"
 	"net"
 	"sync/atomic"
 )
@@ -83,7 +84,17 @@ func (sc *socketConn) IsOpen() bool {
 	if !sc.isValid() {
 		return false
 	}
-	return sc.checkConn() == nil
+	if err := sc.checkConn(); err != nil {
+		if !errors.Is(err, net.ErrClosed) {
+			// The connectivity check failed and the error is not
+			// that the connection is already closed, we need to
+			// close the connection explicitly here to avoid
+			// connection leaks.
+			sc.Close()
+		}
+		return false
+	}
+	return true
 }
 
 // Read implements io.Reader.