Skip to content

Commit 4d97c01

Browse files
committed
Send interrupt on Close on GOOS != windows
Updates #19
1 parent 5856bf0 commit 4d97c01

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Diff for: conn.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"bytes"
66
"errors"
77
"io"
8+
"os"
89
"os/exec"
910
"regexp"
11+
"runtime"
1012
"time"
1113
)
1214

@@ -55,8 +57,19 @@ func (c conn) Start() error {
5557

5658
// Close closes conn's WriteCloser, ReadClosers, and waits for the command to finish.
5759
func (c conn) Close() error {
60+
5861
writeErr := c.WriteCloser.Close()
5962
readErr := c.readerCloser.Close()
63+
var interruptErr error
64+
65+
if runtime.GOOS != "windows" {
66+
// See https://github.com/bep/godartsass/issues/19
67+
interruptErr = c.cmd.Process.Signal(os.Interrupt)
68+
if interruptErr == os.ErrProcessDone {
69+
interruptErr = nil
70+
}
71+
}
72+
6073
cmdErr := c.waitWithTimeout()
6174

6275
if writeErr != nil {
@@ -67,6 +80,10 @@ func (c conn) Close() error {
6780
return readErr
6881
}
6982

83+
if interruptErr != nil {
84+
return interruptErr
85+
}
86+
7087
return cmdErr
7188
}
7289

@@ -79,10 +96,14 @@ func (c conn) waitWithTimeout() error {
7996
go func() { result <- c.cmd.Wait() }()
8097
select {
8198
case err := <-result:
82-
if _, ok := err.(*exec.ExitError); ok {
99+
if eerr, ok := err.(*exec.ExitError); ok {
100+
if eerr.Error() == "signal: interrupt" {
101+
return nil
102+
}
83103
if brokenPipeRe.MatchString(c.stdErr.String()) {
84104
return nil
85105
}
106+
86107
}
87108
return err
88109
case <-time.After(5 * time.Second):

0 commit comments

Comments
 (0)