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

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


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

commit 56a840aa176494c5875cba7faff9dfc16bf8f831
Author: Yuxuan 'fishy' Wang <[email protected]>
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.

Reply via email to