fix: skip post-job hook when executor fails to boot#276
Open
cchristous wants to merge 1 commit into
Open
Conversation
Running the post-job hook through an executor that never started dereferences a nil shell (SIGSEGV), crashing the agent process. Gate it on executorRunning, matching how epilogues are already handled.
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.
Problem
When a job's executor fails to boot, the agent process crashes with a nil-pointer SIGSEGV instead of failing the job cleanly.
Root cause
In
Job.RunWithOptions, the executor is started viaPrepareEnvironment(). When that fails,executorRunningisfalse, so the regular commands and epilogues are correctly skipped — but the post-job hook was called unconditionally afterward:runPostJobHookruns the hook inside the executor (Executor.RunCommandWithOptions), which forDockerComposeExecutor/ShellExecutorcallse.Shell.NewProcessWithOutput(...).e.Shellis only assigned once the executor boots successfully, so on a failed boot it isniland the call dereferences a nil pointer — crashing the whole agent process.Fix
Gate the post-job hook on
executorRunning, matching how the epilogues directly above it are already handled. When the executor never booted, the hook is skipped and the job finishes cleanly as failed (with the existingFailed to prepare executor/Executor failed to boot uplog lines).Test
Adds
Test__PostJobHookSkippedWhenExecutorFailsToPrepare: a stub executor whosePrepare()fails drivesRunWithOptionswith a post-job hook configured, and the test asserts the hook is never attempted (and the job still finishes). The test fails without the guard and passes with it. The existingTest__UsePostJobHookcontinues to cover the success path.