Skip to content

fix: set errors on all commands when context is cancelled in Pipeline.Exec - #2

Open
pistakugli wants to merge 1 commit into
SimsChad12:mainfrom
pistakugli:fix/pipeline-context-cancellation
Open

fix: set errors on all commands when context is cancelled in Pipeline.Exec#2
pistakugli wants to merge 1 commit into
SimsChad12:mainfrom
pistakugli:fix/pipeline-context-cancellation

Conversation

@pistakugli

Copy link
Copy Markdown

Problem

When Pipeline.Exec(ctx) is called with a pre-cancelled context, the commands in the queue don't have their errors set. This causes:

  • Command accumulation on pipeline reuse
  • Memory leaks from unreferenced commands
  • Connection pollution from unclean state

Solution

Added a context check before execution. If the context is already cancelled, we set the context error on all commands and return immediately.

Changes

  • pipeline.go: Added context check in Exec() that sets errors on all commands when context is pre-cancelled
  • pipeline_test.go: Added 3 tests for context cancellation scenarios

Tests

  1. Context cancellation: Verifies all commands get context.Canceled error
  2. Pipeline reuse: Verifies pipeline works correctly after failed Exec
  3. Deadline exceeded: Verifies context.DeadlineExceeded is handled

Acceptance Criteria

  • Pipeline.Exec(ctx) guarantees that the internal command queue is cleared on all exit paths
  • All commands queued during a cancelled Exec have their internal error set to the context error
  • Pipeline reuse after a failed/cancelled Exec starts with a clean slate

Wallet: 0xb7419c92b1d93251c0c85b756b390b29ab8162e0 (Polygon)

….Exec

When Pipeline.Exec is called with a pre-cancelled context, the commands
in the queue now have their errors set to the context error before
returning. This prevents:
- Command accumulation on pipeline reuse
- Memory leaks from unreferenced commands
- Connection pollution from unclean state

Also adds tests for context cancellation, pipeline reuse after
cancellation, and deadline exceeded scenarios.
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.

1 participant