Skip to content

Commit

Permalink
core/bloombits: fix deadlock when matcher session hits an error (bnb-…
Browse files Browse the repository at this point in the history
…chain#1895)

When MatcherSession encounters an error, it attempts to close the session.
Closing waits for all goroutines to finish, including the 'distributor'.
However, the distributor will not exit until all requests have returned.

This patch fixes the issue by delivering the (empty) result to the distributor
before calling Close().
  • Loading branch information
msmania committed Oct 30, 2023
1 parent bb6bdc0 commit 050dad5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/bloombits/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,16 @@ func (s *MatcherSession) Multiplex(batch int, wait time.Duration, mux chan chan
request <- &Retrieval{Bit: bit, Sections: sections, Context: s.ctx}

result := <-request

// Deliver a result before s.Close() to avoid a deadlock
s.deliverSections(result.Bit, result.Sections, result.Bitsets)

if result.Error != nil {
s.errLock.Lock()
s.err = result.Error
s.errLock.Unlock()
s.Close()
}
s.deliverSections(result.Bit, result.Sections, result.Bitsets)
}
}
}

0 comments on commit 050dad5

Please sign in to comment.