Skip to content

Commit

Permalink
Make Echo method to be a really timebound call
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pperiyasamy committed Oct 18, 2023
1 parent cf04722 commit 3e741b7
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e741b7

Please sign in to comment.