From 6fd287e1d55697f28841125c26dbcb62eba27fa8 Mon Sep 17 00:00:00 2001 From: Yan Zhu Date: Fri, 27 Sep 2024 16:57:26 +0800 Subject: [PATCH] Fix a deadlock when leader change if enable leader-only option. Signed-off-by: Yan Zhu --- client/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 10ea757e..e15caa53 100644 --- a/client/client.go +++ b/client/client.go @@ -285,11 +285,11 @@ func (o *ovsdbClient) connect(ctx context.Context, reconnect bool) error { o.logger.V(3).Info("reconnected - restarting monitors") for dbName, db := range o.databases { db.monitorsMutex.Lock() - defer db.monitorsMutex.Unlock() // Purge entire cache if no monitors exist to update dynamically if len(db.monitors) == 0 { db.cache.Purge(db.model) + db.monitorsMutex.Unlock() continue } @@ -299,9 +299,11 @@ func (o *ovsdbClient) connect(ctx context.Context, reconnect bool) error { err := o.monitor(ctx, MonitorCookie{DatabaseName: dbName, ID: id}, true, request) if err != nil { o.resetRPCClient() + db.monitorsMutex.Unlock() return err } } + db.monitorsMutex.Unlock() } }