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

fix: Correct SIGTERM handling. Fixes #10518 #10337 #10033 #10490 #10523

Merged
merged 4 commits into from
Feb 23, 2023
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
24 changes: 8 additions & 16 deletions cmd/argoexec/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package commands

import (
"context"
"os/signal"
"syscall"
"time"

"github.com/argoproj/pkg/stats"
Expand All @@ -16,7 +14,7 @@ func NewWaitCommand() *cobra.Command {
Use: "wait",
Short: "wait for main container to finish and save artifacts",
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
ctx := cmd.Context()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest putting the code related to signal handling here. The current implementation affects all subcommands of argoexec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s intentional, as they’re currently not able to deal with SIGTERM. That said, each one needs to be updated to have this line in them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data was followed up in #12544 (comment)

err := waitContainer(ctx)
if err != nil {
log.Fatalf("%+v", err)
Expand All @@ -32,20 +30,14 @@ func waitContainer(ctx context.Context) error {
defer stats.LogStats()
stats.StartStatsTicker(5 * time.Minute)

// use a function to constrain the scope of ctx
func() {
// this allows us to gracefully shutdown, capturing artifacts
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGTERM)
defer cancel()

// Wait for main container to complete
err := wfExecutor.Wait(ctx)
if err != nil {
wfExecutor.AddError(err)
}
}()
// Wait for main container to complete
err := wfExecutor.Wait(ctx)
if err != nil {
wfExecutor.AddError(err)
}
ctx = context.Background() // don't allow cancellation to impact capture of results, parameters,or artifacts
// Capture output script result
err := wfExecutor.CaptureScriptResult(ctx)
err = wfExecutor.CaptureScriptResult(ctx)
if err != nil {
wfExecutor.AddError(err)
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/argoexec/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/argoproj/argo-workflows/v3/util/errors"

Expand All @@ -13,7 +16,9 @@ import (
)

func main() {
err := commands.NewRootCommand().Execute()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer stop()
err := commands.NewRootCommand().ExecuteContext(ctx)
if err != nil {
if exitError, ok := err.(errors.Exited); ok {
if exitError.ExitCode() >= 0 {
Expand Down