Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of cli: prevent panic on CTRL+C during a question into release/1.5.x #19162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cli: Fixed a panic when the `nomad job restart` command received an interrupt signal while waiting for an answer
```
22 changes: 11 additions & 11 deletions command/job_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ func (c *JobRestartCommand) Run(args []string) int {
c.client.SetNamespace(*job.Namespace)
}

// Handle SIGINT to prevent accidental cancellations of the long-lived
// restart loop. activeCh is blocked while a signal is being handled to
// prevent new work from starting while the user is deciding if they want
// to cancel the command or not.
activeCh := make(chan any)
c.sigsCh = make(chan os.Signal, 1)
signal.Notify(c.sigsCh, os.Interrupt)
defer signal.Stop(c.sigsCh)

go c.handleSignal(c.sigsCh, activeCh)

// Confirm that we should restart a multi-region job in a single region.
if job.IsMultiregion() && !c.autoYes && !c.shouldRestartMultiregion() {
c.Ui.Output("\nJob restart canceled.")
Expand Down Expand Up @@ -326,17 +337,6 @@ func (c *JobRestartCommand) Run(args []string) int {
english.Plural(len(restartAllocs), "allocation", "allocations"),
)))

// Handle SIGINT to prevent accidental cancellations of the long-lived
// restart loop. activeCh is blocked while a signal is being handled to
// prevent new work from starting while the user is deciding if they want
// to cancel the command or not.
activeCh := make(chan any)
c.sigsCh = make(chan os.Signal, 1)
signal.Notify(c.sigsCh, os.Interrupt)
defer signal.Stop(c.sigsCh)

go c.handleSignal(c.sigsCh, activeCh)

// restartErr accumulates the errors that happen in each batch.
var restartErr *multierror.Error

Expand Down