From df04cb007b8ff09603f18c035df5ffc760430bdc Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Fri, 12 Jul 2024 09:12:26 +0000 Subject: [PATCH] Improve code --- sonic_data_client/client_test.go | 4 ++-- sonic_data_client/mixed_db_client.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sonic_data_client/client_test.go b/sonic_data_client/client_test.go index f765b958..539e4cda 100644 --- a/sonic_data_client/client_test.go +++ b/sonic_data_client/client_test.go @@ -558,7 +558,7 @@ func TestRetryHelper(t *testing.T) { exeCount++ if returnError { returnError = false - return fmt.Errorf("connection_reset") + return fmt.Errorf("zmq connection break, endpoint: tcp://127.0.0.1:2234") } return nil }) @@ -596,7 +596,7 @@ func TestRetryHelperReconnect(t *testing.T) { func () (err error) { exeCount++ if exeCount <= 6 { - return fmt.Errorf("connection_reset") + return fmt.Errorf("zmq connection break, endpoint: tcp://127.0.0.1:2234") } return nil }) diff --git a/sonic_data_client/mixed_db_client.go b/sonic_data_client/mixed_db_client.go index da577ebb..ffbb47a8 100644 --- a/sonic_data_client/mixed_db_client.go +++ b/sonic_data_client/mixed_db_client.go @@ -288,11 +288,11 @@ type ActionNeedRetry func() error func RetryHelper(zmqClient swsscommon.ZmqClient, action ActionNeedRetry) error { var retry uint = 0 var retry_delay = time.Duration(RETRY_DELAY_MILLISECOND) * time.Millisecond - ConnectionResetErr := "connection_reset" + ConnectionResetErr := "zmq connection break" for { err := action() if err != nil { - if (err.Error() == ConnectionResetErr) { + if strings.Contains(err.Error(), ConnectionResetErr) { if (retry <= MAX_RETRY_COUNT) { log.V(6).Infof("RetryHelper: connection reset, reconnect and retry later") time.Sleep(retry_delay)