]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/go-plugin/client.go
update vendor and go.mod
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-plugin / client.go
index 679e10ad7591468985f3866ef6f9c93188848edd..bc56559c6328d255a7407e5d0e67330cd3e4bc3c 100644 (file)
@@ -87,6 +87,10 @@ type Client struct {
        // goroutines.
        clientWaitGroup sync.WaitGroup
 
+       // stderrWaitGroup is used to prevent the command's Wait() function from
+       // being called before we've finished reading from the stderr pipe.
+       stderrWaitGroup sync.WaitGroup
+
        // processKilled is used for testing only, to flag when the process was
        // forcefully killed.
        processKilled bool
@@ -590,6 +594,12 @@ func (c *Client) Start() (addr net.Addr, err error) {
        // Create a context for when we kill
        c.doneCtx, c.ctxCancel = context.WithCancel(context.Background())
 
+       // Start goroutine that logs the stderr
+       c.clientWaitGroup.Add(1)
+       c.stderrWaitGroup.Add(1)
+       // logStderr calls Done()
+       go c.logStderr(cmdStderr)
+
        c.clientWaitGroup.Add(1)
        go func() {
                // ensure the context is cancelled when we're done
@@ -602,6 +612,10 @@ func (c *Client) Start() (addr net.Addr, err error) {
                pid := c.process.Pid
                path := cmd.Path
 
+               // wait to finish reading from stderr since the stderr pipe reader
+               // will be closed by the subsequent call to cmd.Wait().
+               c.stderrWaitGroup.Wait()
+
                // Wait for the command to end.
                err := cmd.Wait()
 
@@ -624,11 +638,6 @@ func (c *Client) Start() (addr net.Addr, err error) {
                c.exited = true
        }()
 
-       // Start goroutine that logs the stderr
-       c.clientWaitGroup.Add(1)
-       // logStderr calls Done()
-       go c.logStderr(cmdStderr)
-
        // Start a goroutine that is going to be reading the lines
        // out of stdout
        linesCh := make(chan string)
@@ -936,6 +945,7 @@ var stdErrBufferSize = 64 * 1024
 
 func (c *Client) logStderr(r io.Reader) {
        defer c.clientWaitGroup.Done()
+       defer c.stderrWaitGroup.Done()
        l := c.logger.Named(filepath.Base(c.config.Cmd.Path))
 
        reader := bufio.NewReaderSize(r, stdErrBufferSize)