From 3e741b746481d4c11ffa9d6c1466f7059c96e9d0 Mon Sep 17 00:00:00 2001 From: Periyasamy Palanisamy Date: Wed, 18 Oct 2023 12:40:22 +0200 Subject: [PATCH] Make Echo method to be a really timebound call The client's Echo method invokes o.rpcClient.CallWithContext to send echo to server which again invokes c.Go which writes request into channel buffer synchronizely which is not covered with context timeout. So timeout never triggered and inactivity check is indefinitely waiting for the echo reply. Hence this commit makes Echo method itslef to honor the context timeout at any case. Signed-off-by: Periyasamy Palanisamy --- client/client.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/client/client.go b/client/client.go index 8c9a1051..0c1a423a 100644 --- a/client/client.go +++ b/client/client.go @@ -1080,16 +1080,27 @@ func (o *ovsdbClient) Echo(ctx context.Context) error { if o.rpcClient == nil { return ErrNotConnected } - err := o.rpcClient.CallWithContext(ctx, "echo", args, &reply) - if err != nil { - if err == rpc2.ErrShutdown { - return ErrNotConnected + errCh := make(chan error) + go func() { + err := o.rpcClient.CallWithContext(ctx, "echo", args, &reply) + if err != nil { + if err == rpc2.ErrShutdown { + errCh <- ErrNotConnected + return + } } + if !reflect.DeepEqual(args, reply) { + errCh <- fmt.Errorf("incorrect server response: %v, %v", args, reply) + return + } + errCh <- nil + }() + select { + case err := <-errCh: + return err + case <-ctx.Done(): + return ctx.Err() } - if !reflect.DeepEqual(args, reply) { - return fmt.Errorf("incorrect server response: %v, %v", args, reply) - } - return nil } // watchForLeaderChange will trigger a reconnect if the connected endpoint