From ceb1719f9a3614ae3fc70e3a327bad21a8d5d1c3 Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Fri, 14 Aug 2026 17:55:20 +0200 Subject: [PATCH] [client] Serialize wasm SSH session startup with Close Co-Authored-By: Claude Fable 5 --- client/wasm/internal/ssh/client.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/wasm/internal/ssh/client.go b/client/wasm/internal/ssh/client.go index 83170bfc3..31b9c5fe2 100644 --- a/client/wasm/internal/ssh/client.go +++ b/client/wasm/internal/ssh/client.go @@ -119,8 +119,13 @@ func (c *Client) getAuthMethods(jwtToken string) ([]ssh.AuthMethod, error) { return []ssh.AuthMethod{ssh.PublicKeys(signer)}, nil } -// StartSession starts an SSH session with PTY +// StartSession starts an SSH session with PTY. It holds the client lock for +// the whole startup so Close cannot tear the client down mid-setup and the +// new session cannot be installed into an already closed client. func (c *Client) StartSession(cols, rows int) error { + c.mu.Lock() + defer c.mu.Unlock() + if c.sshClient == nil { return fmt.Errorf("SSH client not connected") } @@ -130,8 +135,6 @@ func (c *Client) StartSession(cols, rows int) error { return err } - c.mu.Lock() - defer c.mu.Unlock() c.session = pty.Session c.stdin = pty.Stdin c.stdout = pty.Stdout