Skip to content

Commit

Permalink
fix: leaky goroutines when ctx is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
coadler committed Sep 2, 2021
1 parent 3ada696 commit 63d04c2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r remoteExec) Start(ctx context.Context, c Command) (Process, error) {
conn: r.conn,
cmd: c,
pid: pidHeader.Pid,
done: make(chan error),
done: make(chan error, 1),
stderr: newPipe(),
stdout: newPipe(),
stdin: stdin,
Expand Down Expand Up @@ -154,6 +154,7 @@ func newPipe() pipe {

func (r remoteProcess) listen(ctx context.Context) {
defer r.conn.Close(websocket.StatusNormalClosure, "normal closure")
defer close(r.done)

exitCode := make(chan int, 1)
var eg errgroup.Group
Expand Down Expand Up @@ -206,9 +207,7 @@ func (r remoteProcess) listen(ctx context.Context) {
case exitCode := <-exitCode:
if exitCode != 0 {
r.done <- ExitError{Code: exitCode}
return
}
r.done <- nil
default:
r.done <- err
}
Expand Down

0 comments on commit 63d04c2

Please sign in to comment.