Skip to content

Commit e66f8bb

Browse files
authored
Respect context cancel (#9)
1 parent 77b7026 commit e66f8bb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (r remoteExec) Start(ctx context.Context, c Command) (Process, error) {
6060
return nil, xerrors.Errorf("failed to parse pid message: %w", err)
6161
}
6262
rp := remoteProcess{
63+
ctx: ctx,
6364
conn: r.conn,
6465
pid: pidHeader.Pid,
6566
done: make(chan error),
@@ -75,6 +76,7 @@ func (r remoteExec) Start(ctx context.Context, c Command) (Process, error) {
7576
}
7677

7778
type remoteProcess struct {
79+
ctx context.Context
7880
conn *websocket.Conn
7981
pid int
8082
done chan error
@@ -235,7 +237,12 @@ func (r remoteProcess) Resize(ctx context.Context, rows, cols uint16) error {
235237
}
236238

237239
func (r remoteProcess) Wait() error {
238-
return <-r.done
240+
select {
241+
case err := <-r.done:
242+
return err
243+
case <-r.ctx.Done():
244+
return r.ctx.Err()
245+
}
239246
}
240247

241248
func (r remoteProcess) Close() error {

localexec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (l LocalExecer) Start(ctx context.Context, c Command) (Process, error) {
7373
process localProcess
7474
err error
7575
)
76-
process.cmd = exec.Command(c.Command, c.Args...)
76+
process.cmd = exec.CommandContext(ctx, c.Command, c.Args...)
7777
process.cmd.Env = c.Env
7878
process.cmd.Dir = c.WorkingDir
7979

0 commit comments

Comments
 (0)