From 6f77acc111e1ed2e2223ab405c2bd82c4ae4bb0f Mon Sep 17 00:00:00 2001 From: Youngteac Hong Date: Mon, 16 Dec 2024 17:47:33 +0900 Subject: [PATCH] Fix panic in pubsub by deleting subs in callback --- server/backend/sync/memory/pubsub.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/backend/sync/memory/pubsub.go b/server/backend/sync/memory/pubsub.go index ad7a7879b..0858e104e 100644 --- a/server/backend/sync/memory/pubsub.go +++ b/server/backend/sync/memory/pubsub.go @@ -145,12 +145,14 @@ func (m *PubSub) Unsubscribe( if subs, ok := m.subscriptionsMap.Get(docKey); ok { subs.Delete(sub.ID()) - if subs.Len() == 0 { - m.subscriptionsMap.Delete(docKey, func(subs *Subscriptions, exists bool) bool { - subs.Close() - return exists - }) - } + m.subscriptionsMap.Delete(docKey, func(subs *Subscriptions, exists bool) bool { + if !exists || 0 < subs.Len() { + return false + } + + subs.Close() + return true + }) } if logging.Enabled(zap.DebugLevel) {