Skip to content

Commit

Permalink
Merge pull request #4362 from tonistiigi/history-listener-hang
Browse files Browse the repository at this point in the history
llbsolver: fix possible deadlock in history listen
  • Loading branch information
tonistiigi authored Oct 23, 2023
2 parents a9e3985 + 1ed9931 commit ef9ae3a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion solver/llbsolver/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,21 +762,30 @@ func (h *HistoryQueue) Listen(ctx context.Context, req *controlapi.BuildHistoryR
}()
}

// make a copy of events for active builds so we don't keep a lock during grpc send
actives := make([]*controlapi.BuildHistoryEvent, 0, len(h.active))

for _, e := range h.active {
if req.Ref != "" && e.Ref != req.Ref {
continue
}
if _, ok := h.deleted[e.Ref]; ok {
continue
}
sub.send(&controlapi.BuildHistoryEvent{
actives = append(actives, &controlapi.BuildHistoryEvent{
Type: controlapi.BuildHistoryEventType_STARTED,
Record: e,
})
}

h.mu.Unlock()

for _, e := range actives {
if err := f(e); err != nil {
return err
}
}

if !req.ActiveOnly {
events := []*controlapi.BuildHistoryEvent{}
if err := h.opt.DB.View(func(tx *bolt.Tx) error {
Expand Down

0 comments on commit ef9ae3a

Please sign in to comment.