From a0a80852eb2b6a4d0c286f9786982e7f562878a2 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sat, 31 May 2025 12:57:18 -0400 Subject: [PATCH] fix: connect to stdout fd after starting an ssh shell this avoids a race condition that would happen if the goroutine tried to read a file descriptor that wasn't open properly and would lose frame delivery --- agent/internal/sshutil/connect.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/internal/sshutil/connect.go b/agent/internal/sshutil/connect.go index 1aa45b1..6ac8c2d 100644 --- a/agent/internal/sshutil/connect.go +++ b/agent/internal/sshutil/connect.go @@ -120,9 +120,6 @@ func StartWebSSH(agent *tsnet.TSAgent, params SSHConnectPayload) { } }() - // This spawns 2 goroutins for stdout and stderr - dispatchSSHStdout(params.SessionId, ctx.Stdout, ctx.Stderr) - // Spin up a shell and wait for the pty to terminate err = sess.Shell() if err != nil { @@ -131,6 +128,9 @@ func StartWebSSH(agent *tsnet.TSAgent, params SSHConnectPayload) { return } + // This spawns 2 goroutins for stdout and stderr + dispatchSSHStdout(params.SessionId, ctx.Stdout, ctx.Stderr) + log.Info("Opened an SSH PTY for %s", params.SessionId) sess.Wait() sess.Close()