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:
parent
1d0bb790f0
commit
9769cd3522
1 changed files with 10 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue