From 8158dd2edc0e51625e25a106cc316965f2c9e521 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Mon, 19 Sep 2022 17:16:54 -0700 Subject: [PATCH] cmd/tsconnect: allow SSH connection timeout to be overridden 5 seconds may not be enough if we're still loading the derp map and connecting to a slow machine. Updates #5693 Signed-off-by: Mihai Parparita --- cmd/tsconnect/src/lib/ssh.ts | 3 +++ cmd/tsconnect/src/types/wasm_js.d.ts | 2 ++ cmd/tsconnect/wasm/wasm_js.go | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/tsconnect/src/lib/ssh.ts b/cmd/tsconnect/src/lib/ssh.ts index defd9b739..f489bb5b2 100644 --- a/cmd/tsconnect/src/lib/ssh.ts +++ b/cmd/tsconnect/src/lib/ssh.ts @@ -5,6 +5,8 @@ import { WebLinksAddon } from "xterm-addon-web-links" export type SSHSessionDef = { username: string hostname: string + /** Defaults to 5 seconds */ + timeoutSeconds?: number } export function runSSHSession( @@ -62,6 +64,7 @@ export function runSSHSession( } onDone() }, + timeoutSeconds: def.timeoutSeconds, }) // Make terminal and SSH session track the size of the containing DOM node. diff --git a/cmd/tsconnect/src/types/wasm_js.d.ts b/cmd/tsconnect/src/types/wasm_js.d.ts index c9dd84230..86d5cb245 100644 --- a/cmd/tsconnect/src/types/wasm_js.d.ts +++ b/cmd/tsconnect/src/types/wasm_js.d.ts @@ -23,6 +23,8 @@ declare global { setReadFn: (readFn: (data: string) => void) => void rows: number cols: number + /** Defaults to 5 seconds */ + timeoutSeconds?: number onDone: () => void } ): IPNSSHSession diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index fd5a46da4..731d6d994 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -360,6 +360,10 @@ func (s *jsSSHSession) Run() { setReadFn := s.termConfig.Get("setReadFn") rows := s.termConfig.Get("rows").Int() cols := s.termConfig.Get("cols").Int() + timeoutSeconds := 5.0 + if jsTimeoutSeconds := s.termConfig.Get("timeoutSeconds"); jsTimeoutSeconds.Type() == js.TypeNumber { + timeoutSeconds = jsTimeoutSeconds.Float() + } onDone := s.termConfig.Get("onDone") defer onDone.Invoke() @@ -367,7 +371,7 @@ func (s *jsSSHSession) Run() { writeErrorFn.Invoke(fmt.Sprintf("%s Error: %v\r\n", label, err)) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds*float64(time.Second))) defer cancel() c, err := s.jsIPN.dialer.UserDial(ctx, "tcp", net.JoinHostPort(s.host, "22")) if err != nil {