From 77da685612d8aa6bd28a92cc88761a50a6abe868 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Tue, 25 Apr 2023 11:44:19 +0000 Subject: [PATCH] Reconnecting PTY waits for command output or EOF Signed-off-by: Spike Curtis --- agent/agent.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 9b70506b49936..82f06e66fa2b2 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1036,12 +1036,9 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m <-ctx.Done() _ = process.Kill() }() - go func() { - // If the process dies randomly, we should - // close the pty. - _ = process.Wait() - rpty.Close() - }() + // We don't need to separately monitor for the process exiting. + // When it exits, our ptty.OutputReader() will return EOF after + // reading all process output. if err = a.trackConnGoroutine(func() { buffer := make([]byte, 1024) for {