mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
Fix hanging workspace shutdowns caused by orphaned SSH child processes. Key changes: - Create process groups for non-PTY SSH sessions - Send SIGHUP to entire process group for proper termination - Add 5-second timeout to prevent indefinite blocking Fixes #17108
25 lines
473 B
Go
25 lines
473 B
Go
//go:build !windows
|
|
|
|
package agentssh
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"syscall"
|
|
|
|
"cdr.dev/slog"
|
|
)
|
|
|
|
func cmdSysProcAttr() *syscall.SysProcAttr {
|
|
return &syscall.SysProcAttr{
|
|
Setsid: true,
|
|
}
|
|
}
|
|
|
|
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
|
|
return func() error {
|
|
logger.Debug(ctx, "cmdCancel: sending SIGHUP to process and children", slog.F("pid", cmd.Process.Pid))
|
|
return syscall.Kill(-cmd.Process.Pid, syscall.SIGHUP)
|
|
}
|
|
}
|