Skip to content

Commit

Permalink
Fix panic in pubsub by deleting subs in callback (#1101)
Browse files Browse the repository at this point in the history
This commit addresses a panic error that occurred after the introduction
of a concurrency map in the pubsub by modifying the deletion process of
subscriptions. Now, instead of causing a panic, subs are deleted within
the callback to ensure thread safety and prevent race conditions.
  • Loading branch information
hackerwins authored Dec 16, 2024
1 parent f35cc77 commit 2bd6d39
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions server/backend/sync/memory/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2bd6d39

Please sign in to comment.