Prevent command Kill races from panicking#64
Open
znull wants to merge 3 commits into
Open
Conversation
A command stage can be killed from more than one goroutine. For example, a pipeline context can expire while another stage wrapper notices a resource limit and also calls Kill with its own error. Those errors can have different concrete types. Storing them directly in atomic.Value makes the second store panic with "sync/atomic: store of inconsistently typed value into Value", crashing the process instead of returning a pipeline error to the caller. So, use a small wrapper type to ensure that doesn't happen. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens commandStage.Kill behavior when multiple goroutines attempt to kill the same command with different concrete error types, preventing atomic.Value from panicking and crashing the process. It does so by wrapping kill reasons in a stable concrete type before storing.
Changes:
- Wrap kill reasons in a dedicated
commandKillErrorstruct before storing inatomic.Value. - Route Unix/Windows
Killimplementations through a sharedrecordKillErrorhelper. - Add a unit test intended to ensure different error concrete types can be recorded without panicking.
Show a summary per file
| File | Description |
|---|---|
| pipe/command.go | Introduces the commandKillError wrapper and centralizes kill-error recording; updates error substitution logic to unwrap. |
| pipe/command_windows.go | Switches kill-reason recording to the shared helper to ensure consistent stored type. |
| pipe/command_unix.go | Switches kill-reason recording to the shared helper to ensure consistent stored type. |
| pipe/command_test.go | Adds a test meant to validate storing different concrete error types without atomic.Value type panics. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
When multiple goroutines race to kill the same command, the first kill reason is the one that caused the command to terminate. Preserve that reason instead of allowing a later cleanup or context-cancellation kill to overwrite it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+294
to
298
| ctxErr := s.ctxErr.Load() | ||
| if ctxErr != nil { | ||
| // If the process looks like it was killed by us, substitute | ||
| // `ctxErr` for the process's own exit error. Note that this | ||
| // doesn't do anything on Windows, where the `Signaled()` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A command stage can be killed from more than one goroutine. For example, a pipeline context can expire while another stage wrapper notices a resource limit and also calls Kill with its own error.
Those errors can have different concrete types. Storing them directly in atomic.Value makes the second store panic with "sync/atomic: store of inconsistently typed value into Value", crashing the process instead of returning a pipeline error to the caller.
So, use a small wrapper type to ensure that doesn't happen.