Skip to content

Commit

Permalink
Detach artifact phase context
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJosh9000 committed Jul 25, 2024
1 parent 33e6f61 commit 945dbb7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ func (e *Executor) Run(ctx context.Context) (exitCode int) {
defer stopper()
defer func() { span.FinishWithError(err) }()

// kind of a weird series of events - wrap a context in a cancellation (at the top of the func), then pull the cancellation
// out again, but some of the stuff we need to do in the executor (namely the teardown) needs to be able to "survive"
// a cancellation so we need to be able to pass a cancellable context to the non-teardown stuff, and an uncancellable
// context to the teardown stuff
nonCancelCtx := context.WithoutCancel(ctx)

// Listen for cancellation
go func() {
<-e.cancelCh
Expand All @@ -151,7 +145,11 @@ func (e *Executor) Run(ctx context.Context) (exitCode int) {

// Tear down the environment (and fire pre-exit hook) before we exit
defer func() {
if err = e.tearDown(nonCancelCtx); err != nil {
// kind of a weird series of events - wrap a context in a cancellation (at the top of the func), then pull the cancellation
// out again, but some of the stuff we need to do in the executor (namely the teardown) needs to be able to "survive"
// a cancellation so we need to be able to pass a cancellable context to the non-teardown stuff, and an uncancellable
// context to the teardown stuff
if err := e.tearDown(context.WithoutCancel(ctx)); err != nil {
e.shell.Errorf("Error tearing down job executor: %v", err)

// this gets passed back via the named return
Expand Down Expand Up @@ -237,8 +235,10 @@ func (e *Executor) Run(ctx context.Context) (exitCode int) {
span.RecordError(commandErr)
}

// Only upload artifacts as part of the command phase
if err = e.artifactPhase(ctx); err != nil {
// Only upload artifacts as part of the command phase.
// The artifacts might be relevant for debugging job timeouts, so
// artifact phase shouldn't be subject to cancellation.
if err = e.artifactPhase(context.WithoutCancel(ctx)); err != nil {
e.shell.Errorf("%v", err)

if commandErr != nil {
Expand Down

0 comments on commit 945dbb7

Please # to comment.