From f3a27d7f3a9c83c92ccbe5f9a8ee34b09bdc4264 Mon Sep 17 00:00:00 2001 From: Shingo Omura Date: Tue, 29 Sep 2020 21:16:06 +0900 Subject: [PATCH 1/3] kill task handler process and its decendants cleanly when its context is done. --- pkg/worker/worker.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index 0301c39..1832414 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -31,6 +31,7 @@ import ( "strconv" "strings" "sync" + "syscall" "time" "github.com/pfnet-research/pftaskqueue/pkg/apis/taskqueue" @@ -301,7 +302,11 @@ func (w *Worker) runCommand(logger zerolog.Logger, t *task.Task) (task.TaskResul cmdCtx, cmdCtxCancel := context.WithTimeout(w.ctx, t.Spec.ActualTimeout(w.config.TaskHandler.DefaultCommandTimeout)) defer cmdCtxCancel() - cmd := exec.CommandContext(cmdCtx, w.config.TaskHandler.Commands[0], w.config.TaskHandler.Commands[1:]...) + + cmd := exec.Command(w.config.TaskHandler.Commands[0], w.config.TaskHandler.Commands[1:]...) + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + } // Inject workspace path to stdin rStdout, wStdout := io.Pipe() @@ -330,6 +335,9 @@ func (w *Worker) runCommand(logger zerolog.Logger, t *task.Task) (task.TaskResul }() select { case <-cmdCtx.Done(): + if err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL); err != nil { + streamLogger.Error().Int("pid", cmd.Process.Pid).Err(err).Msg("Failed to kill the process and its descendants") + } cmdErr = cmdCtx.Err() case err := <-cmdDone: cmdErr = err From 2fa57f55096d48a2774587146e01b285773aafd7 Mon Sep 17 00:00:00 2001 From: Shingo Omura Date: Tue, 29 Sep 2020 21:29:11 +0900 Subject: [PATCH 2/3] upgrade go version to 1.14 --- .github/workflows/ci.yaml | 4 ++-- .github/workflows/release.yaml | 4 ++-- Dockerfile | 2 +- go.mod | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3b83784..a03abac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.14 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -50,7 +50,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.14 id: go - name: Check out uses: actions/checkout@v2 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 69b7515..d7f9721 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -17,7 +17,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.14 id: go - name: Check out uses: actions/checkout@v2 @@ -42,7 +42,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.13 + go-version: ^1.14 id: go - name: Check out uses: actions/checkout@v2 diff --git a/Dockerfile b/Dockerfile index 7df71d6..531f702 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13.5 as builder +FROM golang:1.14 as builder ARG RELEASE ARG VERSION WORKDIR /workspace diff --git a/go.mod b/go.mod index cc5556a..3624692 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/pfnet-research/pftaskqueue -go 1.13 +go 1.14 require ( github.com/MakeNowJust/heredoc/v2 v2.0.1 From 69e313cc9fd622ae61d79035f57c1f88fa1b9e36 Mon Sep 17 00:00:00 2001 From: Shingo Omura Date: Tue, 29 Sep 2020 21:53:12 +0900 Subject: [PATCH 3/3] drop windows support. --- .goreleaser.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3947af3..0e14cc1 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,7 +9,6 @@ builds: binary: pftaskqueue goos: - linux - - windows - darwin goarch: - amd64