From e1b1ab7ef6c3f4fb9db10d9e04fc33b7cd9edac0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 31 May 2021 17:37:41 -0400 Subject: [PATCH] envoy: start timeout func after validation This removes the need to check arg length in the timeout function. --- .../connect_envoy_pipe-bootstrap.go | 22 +++++++++---------- .../connect_envoy_pipe-bootstrap_test.go | 1 - 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.go b/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.go index 71d0969f1f..d9b816f69f 100644 --- a/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.go +++ b/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.go @@ -6,8 +6,9 @@ import ( "os" "time" - "github.com/hashicorp/consul/command/flags" "github.com/mitchellh/cli" + + "github.com/hashicorp/consul/command/flags" ) func New(ui cli.Ui) *cmd { @@ -27,23 +28,21 @@ func (c *cmd) init() { } func (c *cmd) Run(args []string) int { + // Read from STDIN, write to the named pipe provided in the only positional arg + if len(args) != 1 { + c.UI.Error("Expecting named pipe path as argument") + return 1 + } + // This should never be alive for very long. In case bad things happen and // Envoy never starts limit how long we live before just exiting so we can't // accumulate tons of these zombie children. time.AfterFunc(10*time.Second, func() { // Force cleanup - if len(args) > 0 { - os.RemoveAll(args[0]) - } + os.RemoveAll(args[0]) os.Exit(99) }) - // Read from STDIN, write to the named pipe provided in the only positional arg - if len(args) != 1 { - c.UI.Error("Expecting named pipe path as argument") - return 1 - } - // WRONLY is very important here - the open() call will block until there is a // reader (Envoy) if we open it with RDWR though that counts as an opener and // we will just send the data to ourselves as the first opener and so only @@ -60,8 +59,7 @@ func (c *cmd) Run(args []string) int { return 1 } - err = f.Close() - if err != nil { + if err = f.Close(); err != nil { c.UI.Error(err.Error()) return 1 } diff --git a/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap_test.go b/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap_test.go index 8f6ee44516..76ed3157c9 100644 --- a/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap_test.go +++ b/command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap_test.go @@ -8,7 +8,6 @@ import ( ) func TestConnectEnvoyPipeBootstrapCommand_noTabs(t *testing.T) { - t.Parallel() if strings.ContainsRune(New(cli.NewMockUi()).Help(), '\t') { t.Fatal("help has tabs") }