Skip to content

Commit cbd62e0

Browse files
committed
prevent goleak, docs
1 parent 80bd12c commit cbd62e0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

agent/agentssh/agentssh.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,10 @@ func (s *Server) Close() error {
10601060
// Guard against multiple calls to Close and
10611061
// accepting new connections during close.
10621062
if s.closing != nil {
1063+
closing := s.closing
10631064
s.mu.Unlock()
1064-
return xerrors.New("server is closing")
1065+
<-closing
1066+
return xerrors.New("server is closed")
10651067
}
10661068
s.closing = make(chan struct{})
10671069

agent/agentssh/exec_windows.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ func cmdSysProcAttr() *syscall.SysProcAttr {
1515
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
1616
return func() error {
1717
logger.Debug(ctx, "cmdCancel: killing process", slog.F("pid", cmd.Process.Pid))
18+
// Windows doesn't support sending signals to process groups, so we
19+
// have to kill the process directly. In the future, we may want to
20+
// implement a more sophisticated solution for process groups on
21+
// Windows, but for now, this is a simple way to ensure that the
22+
// process is terminated when the context is cancelled.
1823
return cmd.Process.Kill()
19-
// return cmd.Process.Signal(os.Interrupt)
2024
}
2125
}

0 commit comments

Comments
 (0)