@@ -255,6 +255,12 @@ func (o *ovsdbClient) connect(ctx context.Context, reconnect bool) error {
255255 if err != nil {
256256 return err
257257 }
258+ ctx := context .Background ()
259+ var cancel context.CancelFunc
260+ if o .options .timeout != 0 {
261+ ctx , cancel = context .WithTimeout (ctx , o .options .timeout )
262+ defer cancel ()
263+ }
258264 if sid , err := o .tryEndpoint (ctx , u ); err != nil {
259265 o .resetRPCClient ()
260266 connectErrors = append (connectErrors ,
@@ -296,6 +302,8 @@ func (o *ovsdbClient) connect(ctx context.Context, reconnect bool) error {
296302 // Restart all monitors; each monitor will handle purging
297303 // the cache if necessary
298304 for id , request := range db .monitors {
305+ ctx , cancel := context .WithTimeout (context .Background (), o .options .timeout )
306+ defer cancel ()
299307 err := o .monitor (ctx , MonitorCookie {DatabaseName : dbName , ID : id }, true , request )
300308 if err != nil {
301309 o .resetRPCClient ()
@@ -1161,8 +1169,6 @@ func (o *ovsdbClient) watchForLeaderChange() error {
11611169 if sid == activeEndpoint .serverID {
11621170 o .logger .V (3 ).Info ("endpoint lost leader, reconnecting" ,
11631171 "endpoint" , activeEndpoint .address , "sid" , sid )
1164- // don't immediately reconnect to the active endpoint since it's no longer leader
1165- o .moveEndpointLast (0 )
11661172 o ._disconnect ()
11671173 } else {
11681174 o .logger .V (3 ).Info ("endpoint lost leader but had unexpected server ID" ,
@@ -1263,9 +1269,7 @@ func (o *ovsdbClient) handleDisconnectNotification() {
12631269 db .deferUpdates = true
12641270 db .cacheMutex .Unlock ()
12651271 }
1266- ctx , cancel := context .WithTimeout (context .Background (), o .options .timeout )
1267- defer cancel ()
1268- err := o .connect (ctx , true )
1272+ err := o .connect (context .Background (), true )
12691273 if err != nil {
12701274 if suppressionCounter < 5 {
12711275 o .logger .V (2 ).Error (err , "failed to reconnect" )
@@ -1278,6 +1282,7 @@ func (o *ovsdbClient) handleDisconnectNotification() {
12781282 return err
12791283 }
12801284 o .logger .V (3 ).Info ("connection lost, reconnecting" , "endpoint" , o .endpoints [0 ].address )
1285+ o .moveEndpointLast (0 )
12811286 err := backoff .Retry (connect , o .options .backoff )
12821287 if err != nil {
12831288 // TODO: We should look at passing this back to the
0 commit comments