Skip to content

Commit 2f86b32

Browse files
authored
Merge pull request #16 from chatbotkit/next
Release go-sdk
2 parents 53e0cb6 + 442f2d9 commit 2f86b32

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

agent/tools.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os"
1313
"os/exec"
1414
"strings"
15-
"syscall"
1615
"time"
1716
)
1817

@@ -357,14 +356,11 @@ func execCommandHandler(ctx context.Context, args map[string]interface{}) (inter
357356

358357
cmd := exec.CommandContext(ctx, "sh", "-c", command)
359358

360-
// Start the command in its own process group so that cancellation kills
361-
// all child processes (e.g. sleep, long-running builds) - not just the
362-
// top-level shell.
363-
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
364-
cmd.Cancel = func() error {
365-
// Send SIGKILL to the entire process group (negative PID).
366-
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
367-
}
359+
// Ensure cancellation kills all child processes (e.g. sleep, long-running
360+
// builds), not just the top-level shell. The mechanism is platform
361+
// specific (process groups + SIGKILL on Unix), so it lives in
362+
// tools_unix.go / tools_windows.go.
363+
configureCancellation(cmd)
368364

369365
var stdout, stderr bytes.Buffer
370366
cmd.Stdout = &stdout

agent/tools_unix.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build !windows
2+
3+
package agent
4+
5+
import (
6+
"os/exec"
7+
"syscall"
8+
)
9+
10+
// configureCancellation starts the command in its own process group and, on
11+
// cancellation, sends SIGKILL to the entire group (negative PID) so that all
12+
// child processes are terminated - not just the top-level shell.
13+
func configureCancellation(cmd *exec.Cmd) {
14+
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
15+
cmd.Cancel = func() error {
16+
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
17+
}
18+
}

agent/tools_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build windows
2+
3+
package agent
4+
5+
import "os/exec"
6+
7+
// configureCancellation is a no-op on Windows, which has no process-group /
8+
// SIGKILL semantics equivalent to the Unix implementation. Cancellation falls
9+
// back to the default exec.CommandContext behaviour (Process.Kill on the
10+
// top-level process).
11+
func configureCancellation(cmd *exec.Cmd) {}

0 commit comments

Comments
 (0)