diff options
author | Yuxuan 'fishy' Wang <yuxuan.wang@reddit.com> | 2022-02-03 10:44:53 -0800 |
---|---|---|
committer | Yuxuan 'fishy' Wang <yuxuan.wang@reddit.com> | 2022-02-03 16:12:06 -0800 |
commit | 56a840aa176494c5875cba7faff9dfc16bf8f831 (patch) | |
tree | 1b1b496ae2acb5408bcb9db3c10af206d6b73cf0 | |
parent | b9fe9c2417f26fa6e1d9383b8fa9d50ff9a96d65 (diff) | |
download | thrift-56a840aa176494c5875cba7faff9dfc16bf8f831.tar.gz |
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.
-rw-r--r-- | lib/go/thrift/socket_conn.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/go/thrift/socket_conn.go b/lib/go/thrift/socket_conn.go index 5619d9626..bbb5b7d15 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. |