This is an automated email from the ASF dual-hosted git repository. dockerzhang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push: new c07316253e [INLONG-10292][SDK] Fix panic in connpool.UpdateEndpoints() of Golang SDK (#10295) c07316253e is described below commit c07316253e06a17d2dda20e26cc487d5691e58e2 Author: gunli <24350...@qq.com> AuthorDate: Wed May 29 16:23:43 2024 +0800 [INLONG-10292][SDK] Fix panic in connpool.UpdateEndpoints() of Golang SDK (#10295) Co-authored-by: gunli <gu...@tencent.com> --- .../dataproxy-sdk-golang/connpool/connpool.go | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/connpool/connpool.go b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/connpool/connpool.go index ff3faa033e..259159af27 100755 --- a/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/connpool/connpool.go +++ b/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/connpool/connpool.go @@ -20,6 +20,7 @@ import ( "context" "errors" "math" + "runtime/debug" "sync" "time" @@ -181,7 +182,7 @@ func (p *connPool) Put(conn gnet.Conn, err error) { return case <-time.After(1 * time.Second): // connChan is full, close the new conn - newConn.Close() + _ = newConn.Close() return } } @@ -195,6 +196,13 @@ func (p *connPool) Put(conn gnet.Conn, err error) { } func (p *connPool) UpdateEndpoints(all, add, del []string) { + defer func() { + if rec := recover(); rec != nil { + p.log.Errorf("panic when update endpoints:", rec) + p.log.Error(string(debug.Stack())) + } + }() + if len(all) == 0 { return } @@ -226,7 +234,7 @@ func (p *connPool) UpdateEndpoints(all, add, del []string) { continue case <-time.After(1 * time.Second): // connChan is full, close the new conn - conn.Close() + _ = conn.Close() continue } } @@ -251,6 +259,12 @@ func (p *connPool) UpdateEndpoints(all, add, del []string) { break } + remoteAddr := conn.RemoteAddr() + if remoteAddr == nil { + CloseConn(conn, 0) + continue + } + addr := conn.RemoteAddr().String() _, ok = delEndpoints[addr] if ok { @@ -269,7 +283,7 @@ func (p *connPool) NumPooled() int { // CloseConn closes a connection after a duration of time func CloseConn(conn gnet.Conn, after time.Duration) { if after <= 0 { - conn.Close() + _ = conn.Close() return } @@ -277,10 +291,10 @@ func CloseConn(conn gnet.Conn, after time.Duration) { go func() { select { case <-time.After(after): - conn.Close() + _ = conn.Close() return case <-ctx.Done(): - conn.Close() + _ = conn.Close() return } }()