Skip to content

Commit

Permalink
upon callback failure wait 5s for main solve to fail
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Campbell <ijc@docker.com>
  • Loading branch information
Ian Campbell committed Jul 30, 2018
1 parent c4b500e commit 7fc8ee2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion client/solve.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, build buildCB,
return s.Run(statusContext, grpchijack.Dialer(c.controlClient()))
})

solveCtx, cancelSolve := context.WithCancel(ctx)
var res *SolveResponse
eg.Go(func() error {
ctx := solveCtx
defer cancelSolve()

defer func() { // make sure the Status ends cleanly on build errors
go func() {
<-time.After(3 * time.Second)
Expand Down Expand Up @@ -159,7 +163,21 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, build buildCB,

if build != nil {
eg.Go(func() error {
return build(ref, s)
err := build(ref, s)
if err == nil {
return nil
}

// If the callback failed then we wait up to
// 5s for the main solve to end before failing
// this goroutine.
select {
case <-solveCtx.Done():
case <-time.After(5 * time.Second):
cancelSolve()
}

return err
})
}

Expand Down

0 comments on commit 7fc8ee2

Please sign in to comment.