Skip to content

Commit c4d3cb8

Browse files
committed
Fix cancel
1 parent 444decb commit c4d3cb8

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"sync"
1111
"sync/atomic"
12-
"syscall"
1312
"time"
1413

1514
"github.com/robfig/cron/v3"
@@ -157,9 +156,7 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
157156
cmd := cmdPty.AsExec()
158157
cmd.SysProcAttr = cmdSysProcAttr()
159158
cmd.WaitDelay = script.TimeoutSeconds + (10 * time.Second)
160-
cmd.Cancel = func() error {
161-
return syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
162-
}
159+
cmd.Cancel = cmdCancel(cmd)
163160

164161
send, flushAndClose := agentsdk.LogsSender(script.LogSourceID, r.PatchLogs, logger)
165162
// If ctx is canceled here (or in a writer below), we may be

agent/agentscripts/agentscripts_other.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
package agentscripts
44

5-
import "syscall"
5+
import (
6+
"os/exec"
7+
"syscall"
8+
)
69

710
func cmdSysProcAttr() *syscall.SysProcAttr {
811
return &syscall.SysProcAttr{
912
Setsid: true,
1013
}
1114
}
15+
16+
func cmdCancel(cmd *exec.Cmd) func() error {
17+
return func() error {
18+
return syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
19+
}
20+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
package agentscripts
22

3-
import "syscall"
3+
import (
4+
"os/exec"
5+
"syscall"
6+
)
47

58
func cmdSysProcAttr() *syscall.SysProcAttr {
69
return &syscall.SysProcAttr{}
710
}
11+
12+
func cmdCancel(cmd *exec.Cmd) func() error {
13+
return func() error {
14+
return nil
15+
}
16+
}

0 commit comments

Comments
 (0)