Skip to content

Commit

Permalink
svs: fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Feb 6, 2025
1 parent 5eae27d commit 4514685
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion std/sync/svs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ func (s *SvSync) GetBootTime() uint64 {
}

func (s *SvSync) onReceiveStateVector(sv *spec_svs.StateVector) {
// Deliver the updates after this call is done
// This ensures the mutex is not held during the callback
// This function, in turn, runs on our main goroutine, so
// that ensures the updates are delivered in order.
var updates []SvSyncUpdate
defer func() {
for _, update := range updates {
s.o.OnUpdate(update)
}
}()

s.mutex.Lock()
defer s.mutex.Unlock()

Expand Down Expand Up @@ -228,7 +239,7 @@ func (s *SvSync) onReceiveStateVector(sv *spec_svs.StateVector) {
s.mtime[hash] = time.Now()

// Notify the application of the update
s.o.OnUpdate(SvSyncUpdate{
updates = append(updates, SvSyncUpdate{
Name: node.Name,
Boot: entry.BootstrapTime,
High: entry.SeqNo,
Expand Down

0 comments on commit 4514685

Please sign in to comment.