summaryrefslogtreecommitdiff
path: root/plugins.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2021-01-23 15:16:57 -0500
committerDave Henderson <dhenderson@gmail.com>2021-01-23 16:59:01 -0500
commitdab034d8edaabd1c183f99c33815dae151af6ab4 (patch)
tree81e07d096c7215f0d5a04ba7c30f4b553311b76f /plugins.go
parentf20592a0422a12774474e61f28dbcade280a5909 (diff)
Fix race condition in signal handling
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'plugins.go')
-rw-r--r--plugins.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/plugins.go b/plugins.go
index 4beedd3a..789fca96 100644
--- a/plugins.go
+++ b/plugins.go
@@ -85,19 +85,28 @@ func (p *plugin) run(args ...interface{}) (interface{}, error) {
outBuf := &bytes.Buffer{}
c.Stdout = outBuf
+ start := time.Now()
+ err := c.Start()
+ if err != nil {
+ return nil, err
+ }
+
// make sure all signals are propagated
sigs := make(chan os.Signal, 1)
signal.Notify(sigs)
go func() {
- // Pass signals to the sub-process
- sig := <-sigs
- if c.Process != nil {
- // nolint: gosec
- _ = c.Process.Signal(sig)
+ select {
+ case sig := <-sigs:
+ // Pass signals to the sub-process
+ if c.Process != nil {
+ // nolint: gosec
+ _ = c.Process.Signal(sig)
+ }
+ case <-ctx.Done():
}
}()
- start := time.Now()
- err := c.Run()
+
+ err = c.Wait()
elapsed := time.Since(start)
if ctx.Err() != nil {