From 75a38151cd832304c3eec4c002d59d644e597534 Mon Sep 17 00:00:00 2001 From: Sam Batschelet Date: Fri, 24 Feb 2023 16:32:32 -0500 Subject: [PATCH] Simplfy subprocess `Stop` & remove useless test (#2652) --- utils/ulimit/ulimit_test.go | 18 ------------------ vms/rpcchainvm/runtime/subprocess/stopper.go | 19 +++++-------------- 2 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 utils/ulimit/ulimit_test.go diff --git a/utils/ulimit/ulimit_test.go b/utils/ulimit/ulimit_test.go deleted file mode 100644 index 0ffe3aa11934..000000000000 --- a/utils/ulimit/ulimit_test.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package ulimit - -import ( - "testing" - - "github.com/ava-labs/avalanchego/utils/logging" -) - -// Test_SetDefault performs sanity checks for the os default. -func Test_SetDefault(t *testing.T) { - err := Set(DefaultFDLimit, logging.NoLog{}) - if err != nil { - t.Skipf("default fd-limit failed %v", err) - } -} diff --git a/vms/rpcchainvm/runtime/subprocess/stopper.go b/vms/rpcchainvm/runtime/subprocess/stopper.go index 616f9c473c83..5f432bd416fd 100644 --- a/vms/rpcchainvm/runtime/subprocess/stopper.go +++ b/vms/rpcchainvm/runtime/subprocess/stopper.go @@ -20,22 +20,13 @@ func NewStopper(logger logging.Logger, cmd *exec.Cmd) runtime.Stopper { } type stopper struct { - lock sync.Mutex - cmd *exec.Cmd - shutdown bool - + once sync.Once + cmd *exec.Cmd logger logging.Logger } func (s *stopper) Stop(ctx context.Context) { - s.lock.Lock() - defer s.lock.Unlock() - - // subsequent calls to this method are a no-op - if s.shutdown || s.cmd.Process == nil { - return - } - - s.shutdown = true - stop(ctx, s.logger, s.cmd) + s.once.Do(func() { + stop(ctx, s.logger, s.cmd) + }) }