Browse Source

envoy: start timeout func after validation

This removes the need to check arg length in the timeout function.
pull/10324/head
Daniel Nephin 4 years ago
parent
commit
e1b1ab7ef6
  1. 22
      command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.go
  2. 1
      command/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap_test.go

22
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
}

1
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")
}

Loading…
Cancel
Save