diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-plugin/client.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-plugin/client.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/vendor/github.com/hashicorp/go-plugin/client.go b/vendor/github.com/hashicorp/go-plugin/client.go index 679e10a..bc56559 100644 --- a/vendor/github.com/hashicorp/go-plugin/client.go +++ b/vendor/github.com/hashicorp/go-plugin/client.go | |||
@@ -87,6 +87,10 @@ type Client struct { | |||
87 | // goroutines. | 87 | // goroutines. |
88 | clientWaitGroup sync.WaitGroup | 88 | clientWaitGroup sync.WaitGroup |
89 | 89 | ||
90 | // stderrWaitGroup is used to prevent the command's Wait() function from | ||
91 | // being called before we've finished reading from the stderr pipe. | ||
92 | stderrWaitGroup sync.WaitGroup | ||
93 | |||
90 | // processKilled is used for testing only, to flag when the process was | 94 | // processKilled is used for testing only, to flag when the process was |
91 | // forcefully killed. | 95 | // forcefully killed. |
92 | processKilled bool | 96 | processKilled bool |
@@ -590,6 +594,12 @@ func (c *Client) Start() (addr net.Addr, err error) { | |||
590 | // Create a context for when we kill | 594 | // Create a context for when we kill |
591 | c.doneCtx, c.ctxCancel = context.WithCancel(context.Background()) | 595 | c.doneCtx, c.ctxCancel = context.WithCancel(context.Background()) |
592 | 596 | ||
597 | // Start goroutine that logs the stderr | ||
598 | c.clientWaitGroup.Add(1) | ||
599 | c.stderrWaitGroup.Add(1) | ||
600 | // logStderr calls Done() | ||
601 | go c.logStderr(cmdStderr) | ||
602 | |||
593 | c.clientWaitGroup.Add(1) | 603 | c.clientWaitGroup.Add(1) |
594 | go func() { | 604 | go func() { |
595 | // ensure the context is cancelled when we're done | 605 | // ensure the context is cancelled when we're done |
@@ -602,6 +612,10 @@ func (c *Client) Start() (addr net.Addr, err error) { | |||
602 | pid := c.process.Pid | 612 | pid := c.process.Pid |
603 | path := cmd.Path | 613 | path := cmd.Path |
604 | 614 | ||
615 | // wait to finish reading from stderr since the stderr pipe reader | ||
616 | // will be closed by the subsequent call to cmd.Wait(). | ||
617 | c.stderrWaitGroup.Wait() | ||
618 | |||
605 | // Wait for the command to end. | 619 | // Wait for the command to end. |
606 | err := cmd.Wait() | 620 | err := cmd.Wait() |
607 | 621 | ||
@@ -624,11 +638,6 @@ func (c *Client) Start() (addr net.Addr, err error) { | |||
624 | c.exited = true | 638 | c.exited = true |
625 | }() | 639 | }() |
626 | 640 | ||
627 | // Start goroutine that logs the stderr | ||
628 | c.clientWaitGroup.Add(1) | ||
629 | // logStderr calls Done() | ||
630 | go c.logStderr(cmdStderr) | ||
631 | |||
632 | // Start a goroutine that is going to be reading the lines | 641 | // Start a goroutine that is going to be reading the lines |
633 | // out of stdout | 642 | // out of stdout |
634 | linesCh := make(chan string) | 643 | linesCh := make(chan string) |
@@ -936,6 +945,7 @@ var stdErrBufferSize = 64 * 1024 | |||
936 | 945 | ||
937 | func (c *Client) logStderr(r io.Reader) { | 946 | func (c *Client) logStderr(r io.Reader) { |
938 | defer c.clientWaitGroup.Done() | 947 | defer c.clientWaitGroup.Done() |
948 | defer c.stderrWaitGroup.Done() | ||
939 | l := c.logger.Named(filepath.Base(c.config.Cmd.Path)) | 949 | l := c.logger.Named(filepath.Base(c.config.Cmd.Path)) |
940 | 950 | ||
941 | reader := bufio.NewReaderSize(r, stdErrBufferSize) | 951 | reader := bufio.NewReaderSize(r, stdErrBufferSize) |