From 090d9b135ec5c40e0484daf4213fd99d24b07489 Mon Sep 17 00:00:00 2001 From: Mykola Balakin Date: Sat, 17 Oct 2026 19:24:17 +0300 Subject: [PATCH] Shorten the critical section --- src/client/jsonrpc2.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/jsonrpc2.go b/src/client/jsonrpc2.go index ceed337..0fd0093 100644 --- a/src/client/jsonrpc2.go +++ b/src/client/jsonrpc2.go @@ -347,26 +347,30 @@ func (r *JsonRpc2Client) acquireReceiveSubscription(account string) error { func (r *JsonRpc2Client) releaseReceiveSubscription(account string) error { r.receiveSubscriptionsMutex.Lock() - defer r.receiveSubscriptionsMutex.Unlock() sub, ok := r.receiveSubscriptions[account] if !ok { + r.receiveSubscriptionsMutex.Unlock() return nil } sub.refcount-- if sub.refcount > 0 { + r.receiveSubscriptionsMutex.Unlock() return nil } + delete(r.receiveSubscriptions, account) err := r.unsubscribeReceive(account, sub.id) + + r.receiveSubscriptionsMutex.Unlock() + if err != nil { log.Warnf("Couldn't unsubscribed from receive notifications for account %s (subscription=%d): %s", account, sub.id, err.Error()) } else { log.Debugf("Unsubscribed from receive notifications for account %s (subscription=%d)", account, sub.id) } - delete(r.receiveSubscriptions, account) return err }