Skip to content
Permalink
Browse files
cancel step on semaphore context deadline exceeded
  • Loading branch information
bradrydzewski committed Sep 21, 2020
1 parent 3bba1bd commit 1bd1ae3f961ae91b20a92298623ee105e0c377df
Showing 1 changed file with 15 additions and 1 deletion.
@@ -145,10 +145,24 @@ func (e *Execer) exec(ctx context.Context, state *pipeline.State, spec Spec, ste
// the semaphore limits the number of steps that can run
// concurrently. acquire the semaphore and release when
// the pipeline completes.
if err := e.sem.Acquire(ctx, 1); err != nil {
err := e.sem.Acquire(ctx, 1)

// if acquiring the semaphore failed because the context
// deadline exceeded (e.g. the pipeline timed out) the
// state should be canceled.
switch ctx.Err() {
case context.Canceled, context.DeadlineExceeded:
state.Cancel()
return nil
}

// if acquiring the semaphore failed for unexpected reasons
// the pipeline should error.
if err != nil {
log.WithError(err).Errorln("failed to acquire semaphore.")
return err
}

defer func() {
// recover from a panic to ensure the semaphore is
// released to prevent deadlock. we do not expect a

0 comments on commit 1bd1ae3

Please sign in to comment.