Skip to content

Conversation

@Pnkcaht
Copy link
Contributor

@Pnkcaht Pnkcaht commented Jan 26, 2026

Fix: always destroy step on pipeline cancellation

What was happening

When a pipeline step was canceled (e.g. manual cancel or agent shutdown), the step execution would exit early, but DestroyStep was not guaranteed to run.
This could leave backend resources (such as Docker containers) running, resulting in orphaned steps after cancellation.

What this PR changes

This PR ensures that DestroyStep is always executed, regardless of how the step finishes.

  • Guarantees cleanup on success, failure, or cancellation
  • Executes DestroyStep via defer in the step execution path
  • Uses a non-cancelable context to avoid cleanup being interrupted
  • Prevents orphaned backend resources

Why this approach

Cancellation may stop waiting on a step, but it should never skip cleanup.
Ensuring DestroyStep always runs makes step lifecycle handling safer and aligns with expected CI behavior.

This also closes the current gap where cleanup depended on higher-level execution flow.

Implementation overview

sequenceDiagram
    participant Runtime as Pipeline Runtime
    participant Engine as Backend Engine
    participant Ctx as Step Context
    participant Step as Backend Step

    Runtime->>Engine: StartStep
    Engine->>Step: start

    alt Step canceled
        Ctx-->>Runtime: ctx.Done()
        Runtime->>Engine: DestroyStep (background context)
    else Step finishes normally
        Step-->>Engine: exit
        Runtime->>Engine: DestroyStep
    end

    Engine-->>Runtime: cleanup completed
Loading

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 26, 2026

Solved here @6543 I ensured that DestroyStep is always executed, even on cancellation/shutdown, preventing orphaned steps/containers.

image

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 27, 2026

@6543 The change has been made, what do you think?

image

@6543
Copy link
Member

6543 commented Jan 28, 2026

fix included in #6011

@6543 6543 closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants