Skip to content

Commit 225c5f9

Browse files
johnstcndannykopping
authored andcommitted
chore(agent/agentscripts): log command cancellation (#16324)
Relates to coder/internal#329 It's currently unclear where the SIGHUP came from; adding some logging to make it more clear if it happens again in future. --------- Co-authored-by: Danny Kopping <danny@coder.com>
1 parent 3c60f80 commit 225c5f9

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

agent/agentscripts/agentscripts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
290290
cmd = cmdPty.AsExec()
291291
cmd.SysProcAttr = cmdSysProcAttr()
292292
cmd.WaitDelay = 10 * time.Second
293-
cmd.Cancel = cmdCancel(cmd)
293+
cmd.Cancel = cmdCancel(ctx, logger, cmd)
294294

295295
// Expose env vars that can be used in the script for storing data
296296
// and binaries. In the future, we may want to expose more env vars

agent/agentscripts/agentscripts_other.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
package agentscripts
44

55
import (
6+
"context"
67
"os/exec"
78
"syscall"
9+
10+
"cdr.dev/slog"
811
)
912

1013
func cmdSysProcAttr() *syscall.SysProcAttr {
@@ -13,8 +16,9 @@ func cmdSysProcAttr() *syscall.SysProcAttr {
1316
}
1417
}
1518

16-
func cmdCancel(cmd *exec.Cmd) func() error {
19+
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
1720
return func() error {
21+
logger.Debug(ctx, "cmdCancel: sending SIGHUP to process and children", slog.F("pid", cmd.Process.Pid))
1822
return syscall.Kill(-cmd.Process.Pid, syscall.SIGHUP)
1923
}
2024
}
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package agentscripts
22

33
import (
4+
"context"
45
"os"
56
"os/exec"
67
"syscall"
8+
9+
"cdr.dev/slog"
710
)
811

912
func cmdSysProcAttr() *syscall.SysProcAttr {
1013
return &syscall.SysProcAttr{}
1114
}
1215

13-
func cmdCancel(cmd *exec.Cmd) func() error {
16+
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
1417
return func() error {
18+
logger.Debug(ctx, "cmdCancel: sending interrupt to process", slog.F("pid", cmd.Process.Pid))
1519
return cmd.Process.Signal(os.Interrupt)
1620
}
1721
}

0 commit comments

Comments
 (0)