From 2400ba28b1f622358387f648f5e16dbc2223f488 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Wed, 7 Sep 2022 18:22:35 -0700 Subject: [PATCH] cmd/tsconnect: handle terminal resizes before the SSH session is created Store the requested size is a struct field, and use that when actually creating the SSH session. Fixes #5567 Signed-off-by: Mihai Parparita --- cmd/tsconnect/wasm/wasm_js.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index e4cf762bf..0873b6c83 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -343,6 +343,9 @@ type jsSSHSession struct { username string termConfig js.Value session *ssh.Session + + pendingResizeRows int + pendingResizeCols int } func (s *jsSSHSession) Run() { @@ -413,6 +416,14 @@ func (s *jsSSHSession) Run() { return nil })) + // We might have gotten a resize notification since we started opening the + // session, pick up the latest size. + if s.pendingResizeRows != 0 { + rows = s.pendingResizeRows + } + if s.pendingResizeCols != 0 { + cols = s.pendingResizeCols + } err = session.RequestPty("xterm", rows, cols, ssh.TerminalModes{}) if err != nil { @@ -438,6 +449,11 @@ func (s *jsSSHSession) Close() error { } func (s *jsSSHSession) Resize(rows, cols int) error { + if s.session == nil { + s.pendingResizeRows = rows + s.pendingResizeCols = cols + return nil + } return s.session.WindowChange(rows, cols) }