From ea1b1f5a0751cfb65940d2c16d2d71c0fe655b8f Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Tue, 16 Nov 2021 11:21:36 +0000 Subject: [PATCH] Use buffered channel for signal notification Refer to https://pkg.go.dev/os/signal#Notify for more details. Signed-off-by: Martin Hickey --- .github/workflows/build-pr.yml | 4 ++-- cmd/helm/install.go | 6 ++++-- cmd/helm/root_unix.go | 1 + cmd/helm/root_unix_test.go | 1 + cmd/helm/upgrade.go | 6 ++++-- pkg/helmpath/home_unix_test.go | 1 + pkg/helmpath/lazypath_darwin.go | 1 + pkg/helmpath/lazypath_darwin_test.go | 1 + pkg/helmpath/lazypath_unix.go | 1 + pkg/helmpath/lazypath_unix_test.go | 1 + 10 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index d35be3f4b..432a6465e 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -21,8 +21,8 @@ jobs: sudo mv golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64/golangci-lint /usr/local/bin/golangci-lint rm -rf golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64* env: - GOLANGCI_LINT_VERSION: '1.36.0' - GOLANGCI_LINT_SHA256: '9b8856b3a1c9bfbcf3a06b78e94611763b79abd9751c245246787cd3bf0e78a5' + GOLANGCI_LINT_VERSION: '1.43.0' + GOLANGCI_LINT_SHA256: 'f3515cebec926257da703ba0a2b169e4a322c11dc31a8b4656b50a43e48877f4' - name: Test style run: make test-style - name: Run unit tests diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 8b468d2f5..e930b6589 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -253,8 +253,10 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options ctx := context.Background() ctx, cancel := context.WithCancel(ctx) - // Handle SIGTERM - cSignal := make(chan os.Signal) + // Set up channel on which to send signal notifications. + // We must use a buffered channel or risk missing the signal + // if we're not ready to receive when the signal is sent. + cSignal := make(chan os.Signal, 2) signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal diff --git a/cmd/helm/root_unix.go b/cmd/helm/root_unix.go index 3df801e4c..47be08b95 100644 --- a/cmd/helm/root_unix.go +++ b/cmd/helm/root_unix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows /* diff --git a/cmd/helm/root_unix_test.go b/cmd/helm/root_unix_test.go index c62776c2a..36abc0184 100644 --- a/cmd/helm/root_unix_test.go +++ b/cmd/helm/root_unix_test.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows /* diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index a8ff93880..6fc6eb9a1 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -186,8 +186,10 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) - // Handle SIGTERM - cSignal := make(chan os.Signal) + // Set up channel on which to send signal notifications. + // We must use a buffered channel or risk missing the signal + // if we're not ready to receive when the signal is sent. + cSignal := make(chan os.Signal, 2) signal.Notify(cSignal, os.Interrupt, syscall.SIGTERM) go func() { <-cSignal diff --git a/pkg/helmpath/home_unix_test.go b/pkg/helmpath/home_unix_test.go index 6a72152c4..b2a6b7a14 100644 --- a/pkg/helmpath/home_unix_test.go +++ b/pkg/helmpath/home_unix_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows // +build !windows package helmpath diff --git a/pkg/helmpath/lazypath_darwin.go b/pkg/helmpath/lazypath_darwin.go index e112b8337..80477abab 100644 --- a/pkg/helmpath/lazypath_darwin.go +++ b/pkg/helmpath/lazypath_darwin.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build darwin // +build darwin package helmpath diff --git a/pkg/helmpath/lazypath_darwin_test.go b/pkg/helmpath/lazypath_darwin_test.go index 9381a44e2..8c1c91e42 100644 --- a/pkg/helmpath/lazypath_darwin_test.go +++ b/pkg/helmpath/lazypath_darwin_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build darwin // +build darwin package helmpath diff --git a/pkg/helmpath/lazypath_unix.go b/pkg/helmpath/lazypath_unix.go index b4eae9f66..a5afc1237 100644 --- a/pkg/helmpath/lazypath_unix.go +++ b/pkg/helmpath/lazypath_unix.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows && !darwin // +build !windows,!darwin package helmpath diff --git a/pkg/helmpath/lazypath_unix_test.go b/pkg/helmpath/lazypath_unix_test.go index 96d66e7a5..450e95781 100644 --- a/pkg/helmpath/lazypath_unix_test.go +++ b/pkg/helmpath/lazypath_unix_test.go @@ -11,6 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows && !darwin // +build !windows,!darwin package helmpath