From fabf30d8f4a86856388c018d986bd05a80282365 Mon Sep 17 00:00:00 2001 From: djshow832 <873581766@qq.com> Date: Mon, 5 Sep 2022 12:06:25 +0800 Subject: [PATCH 1/2] make channel size 1 --- pkg/proxy/backend/backend_conn_mgr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index aeb63e2a..3b815764 100644 --- a/pkg/proxy/backend/backend_conn_mgr.go +++ b/pkg/proxy/backend/backend_conn_mgr.go @@ -88,7 +88,7 @@ func NewBackendConnManager(connectionID uint64) *BackendConnManager { connectionID: connectionID, cmdProcessor: NewCmdProcessor(), authenticator: &Authenticator{}, - signalReceived: make(chan struct{}), + signalReceived: make(chan struct{}, 1), redirectResCh: make(chan *redirectResult, 1), } } From c2416ed0e6aa71880977da60d3a1bb14fbe409f1 Mon Sep 17 00:00:00 2001 From: djshow832 <873581766@qq.com> Date: Mon, 5 Sep 2022 12:27:41 +0800 Subject: [PATCH 2/2] wait for the channel --- pkg/proxy/backend/backend_conn_mgr.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index 3b815764..158da8f9 100644 --- a/pkg/proxy/backend/backend_conn_mgr.go +++ b/pkg/proxy/backend/backend_conn_mgr.go @@ -292,10 +292,8 @@ func (mgr *BackendConnManager) Redirect(newAddr string) { atomic.StorePointer(&mgr.signal, unsafe.Pointer(&signalRedirect{ newAddr: newAddr, })) - select { - case mgr.signalReceived <- struct{}{}: - default: - } + // Generally, it won't wait because the caller won't send another signal because the last one finishes. + mgr.signalReceived <- struct{}{} } // GetRedirectingAddr implements RedirectableConn.GetRedirectingAddr interface.