Skip to content

Commit

Permalink
client: Monitor fallback only on unsupported rpc
Browse files Browse the repository at this point in the history
Falling back to a previous version of the monitor RPC should only happen
if we get a `unsupported rpc` error from ovsdb-server. Previously we
would fall back on `context deadline exceeded` which is not expected
behaviour

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
  • Loading branch information
dave-tucker committed Oct 14, 2021
1 parent 2270cb7 commit c60a132
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,7 @@ func (o *ovsdbClient) MonitorCancel(ctx context.Context, cookie MonitorCookie) e
// RFC 7047 : monitor
func (o *ovsdbClient) Monitor(ctx context.Context, monitor *Monitor) (MonitorCookie, error) {
cookie := newMonitorCookie(o.primaryDBName)
err := o.monitor(ctx, cookie, false, monitor)
if err != nil && err == ErrUnsupportedRPC {
return cookie, o.monitor(ctx, cookie, false, monitor)
}
return cookie, err
return cookie, o.monitor(ctx, cookie, false, monitor)
}

func (o *ovsdbClient) monitor(ctx context.Context, cookie MonitorCookie, reconnecting bool, monitor *Monitor) error {
Expand Down Expand Up @@ -769,17 +765,17 @@ func (o *ovsdbClient) monitor(ctx context.Context, cookie MonitorCookie, reconne
if err == rpc2.ErrShutdown {
return ErrNotConnected
}
// TODO: Match unsupported RPC method error
if monitor.Method == ovsdb.ConditionalMonitorSinceRPC {
log.Printf("libovsdb: method monitor_cond_since not supported, falling back to monitor_cond: %v", err.Error())
monitor.Method = ovsdb.ConditionalMonitorRPC
// return to ensure that we release any held mutexes, retry must happen from a calling function
return ErrUnsupportedRPC
} else if monitor.Method == ovsdb.ConditionalMonitorRPC {
log.Printf("libovsdb: method monitor_cond not supported, falling back to monitor: %v", err.Error())
monitor.Method = ovsdb.MonitorRPC
// return to ensure that we release any held mutexes, retry must happen from a calling function
return ErrUnsupportedRPC
if err.Error() == "unknown method" {
if monitor.Method == ovsdb.ConditionalMonitorSinceRPC {
log.Printf("libovsdb: method monitor_cond_since not supported, falling back to monitor_cond: %v", err.Error())
monitor.Method = ovsdb.ConditionalMonitorRPC
return o.monitor(ctx, cookie, reconnecting, monitor)
}
if monitor.Method == ovsdb.ConditionalMonitorRPC {
log.Printf("libovsdb: method monitor_cond not supported, falling back to monitor: %v", err.Error())
monitor.Method = ovsdb.MonitorRPC
return o.monitor(ctx, cookie, reconnecting, monitor)
}
}
return err
}
Expand Down

0 comments on commit c60a132

Please sign in to comment.