Skip to content

Commit 63d04c2

Browse files
committed
fix: leaky goroutines when ctx is cancelled
1 parent 3ada696 commit 63d04c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (r remoteExec) Start(ctx context.Context, c Command) (Process, error) {
7575
conn: r.conn,
7676
cmd: c,
7777
pid: pidHeader.Pid,
78-
done: make(chan error),
78+
done: make(chan error, 1),
7979
stderr: newPipe(),
8080
stdout: newPipe(),
8181
stdin: stdin,
@@ -154,6 +154,7 @@ func newPipe() pipe {
154154

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

158159
exitCode := make(chan int, 1)
159160
var eg errgroup.Group
@@ -206,9 +207,7 @@ func (r remoteProcess) listen(ctx context.Context) {
206207
case exitCode := <-exitCode:
207208
if exitCode != 0 {
208209
r.done <- ExitError{Code: exitCode}
209-
return
210210
}
211-
r.done <- nil
212211
default:
213212
r.done <- err
214213
}

0 commit comments

Comments
 (0)