From 28510597e6ddade7d2ecbd0dd7d8c94bea991618 Mon Sep 17 00:00:00 2001 From: whl Date: Fri, 12 May 2023 11:41:58 +0800 Subject: [PATCH 1/3] store nil backendIO after OnConnClose, because OnConnClose may call backendIO conn like ServerAddr() Signed-off-by: whl --- pkg/proxy/backend/backend_conn_mgr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index eb26313a..ce9f59de 100644 --- a/pkg/proxy/backend/backend_conn_mgr.go +++ b/pkg/proxy/backend/backend_conn_mgr.go @@ -636,13 +636,13 @@ func (mgr *BackendConnManager) Close() error { var connErr error var addr string mgr.processLock.Lock() - if backendIO := mgr.backendIO.Swap(nil); backendIO != nil { + if backendIO := mgr.backendIO.Load(); backendIO != nil { addr = backendIO.RemoteAddr().String() connErr = backendIO.Close() } - mgr.processLock.Unlock() - handErr := mgr.handshakeHandler.OnConnClose(mgr) + mgr.backendIO.Store(nil) + mgr.processLock.Unlock() eventReceiver := mgr.getEventReceiver() if eventReceiver != nil { From 19afa4c58b05d55e86f9c7e5629e21e7c10f3d21 Mon Sep 17 00:00:00 2001 From: whl Date: Fri, 12 May 2023 15:45:39 +0800 Subject: [PATCH 2/3] move OnConnClose before Swap, because OnConnClose may call backendIO conn like ServerAddr() Signed-off-by: whl --- pkg/proxy/backend/backend_conn_mgr.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index ce9f59de..f75e9e6a 100644 --- a/pkg/proxy/backend/backend_conn_mgr.go +++ b/pkg/proxy/backend/backend_conn_mgr.go @@ -635,13 +635,12 @@ func (mgr *BackendConnManager) Close() error { var connErr error var addr string + handErr := mgr.handshakeHandler.OnConnClose(mgr) mgr.processLock.Lock() - if backendIO := mgr.backendIO.Load(); backendIO != nil { + if backendIO := mgr.backendIO.Swap(nil); backendIO != nil { addr = backendIO.RemoteAddr().String() connErr = backendIO.Close() } - handErr := mgr.handshakeHandler.OnConnClose(mgr) - mgr.backendIO.Store(nil) mgr.processLock.Unlock() eventReceiver := mgr.getEventReceiver() From 107fe9956685c9558a70b60ab54008114534f9cd Mon Sep 17 00:00:00 2001 From: whl Date: Fri, 12 May 2023 15:47:17 +0800 Subject: [PATCH 3/3] move OnConnClose before Swap, because OnConnClose may call backendIO conn like ServerAddr() Signed-off-by: whl --- pkg/proxy/backend/backend_conn_mgr.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index f75e9e6a..327c8379 100644 --- a/pkg/proxy/backend/backend_conn_mgr.go +++ b/pkg/proxy/backend/backend_conn_mgr.go @@ -633,9 +633,10 @@ func (mgr *BackendConnManager) Close() error { } mgr.wg.Wait() + handErr := mgr.handshakeHandler.OnConnClose(mgr) + var connErr error var addr string - handErr := mgr.handshakeHandler.OnConnClose(mgr) mgr.processLock.Lock() if backendIO := mgr.backendIO.Swap(nil); backendIO != nil { addr = backendIO.RemoteAddr().String()