Skip to content

Commit c2cfe35

Browse files
authored
core/bloombits: fix deadlock when matcher session hits an error (#28184)
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().
1 parent d051ea5 commit c2cfe35

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/bloombits/matcher.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,16 @@ func (s *MatcherSession) Multiplex(batch int, wait time.Duration, mux chan chan
630630
request <- &Retrieval{Bit: bit, Sections: sections, Context: s.ctx}
631631

632632
result := <-request
633+
634+
// Deliver a result before s.Close() to avoid a deadlock
635+
s.deliverSections(result.Bit, result.Sections, result.Bitsets)
636+
633637
if result.Error != nil {
634638
s.errLock.Lock()
635639
s.err = result.Error
636640
s.errLock.Unlock()
637641
s.Close()
638642
}
639-
s.deliverSections(result.Bit, result.Sections, result.Bitsets)
640643
}
641644
}
642645
}

0 commit comments

Comments
 (0)