1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

GO-5748: Fix dead-lock in diff manager init

This commit is contained in:
Sergey 2025-06-04 15:14:03 +02:00
parent 1d0bb790f0
commit 9769cd3522
No known key found for this signature in database
GPG key ID: 3B6BEF79160221C6

View file

@ -61,6 +61,8 @@ type service struct {
lock sync.RWMutex
subscriptions map[string]map[string]subscription
subscriptionBuf []subscription
keyValueStore keyvaluestorage.Storage
spaceCore commonspace.Space
observer keyvalueobserver.Observer
@ -127,13 +129,20 @@ func (s *service) observeChanges(decryptor keyvaluestorage.Decryptor, kvs []inne
continue
}
// s.subscriptionBuf is safe to use without a lock because observeChanges runs only in one goroutine, and this buffer
// isn't used anywhere else
s.subscriptionBuf = s.subscriptionBuf[:0]
s.lock.RLock()
byKey := s.subscriptions[value.Key]
for _, sub := range byKey {
sub.observerFunc(value.Key, value)
s.subscriptionBuf = append(s.subscriptionBuf, sub)
}
s.lock.RUnlock()
for _, sub := range s.subscriptionBuf {
sub.observerFunc(value.Key, value)
}
}
}