From ddf7bfb748d46ee2c888417f96ac8a783fc4756d Mon Sep 17 00:00:00 2001 From: djshow832 Date: Mon, 5 Sep 2022 12:49:23 +0800 Subject: [PATCH] backend: fix the bug that the redirection signal may be discarded (#75) --- pkg/proxy/backend/backend_conn_mgr.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/proxy/backend/backend_conn_mgr.go b/pkg/proxy/backend/backend_conn_mgr.go index aeb63e2a..158da8f9 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), } } @@ -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.