From 32a2a1a24214f9844da30f57f448c06a15f2e3f8 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 7 Jul 2021 18:35:57 +0000 Subject: [PATCH 1/2] chore: Cache SSH connections --- internal/cmd/configssh.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index bb0b39c9..f4598837 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -8,6 +8,7 @@ import ( "os" "os/user" "path/filepath" + "runtime" "sort" "strings" @@ -208,7 +209,7 @@ func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWi func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath string, tunnel bool) string { if tunnel { - return fmt.Sprintf( + host := fmt.Sprintf( `Host coder.%s HostName coder.%s ProxyCommand %s tunnel %s 12213 stdio @@ -217,6 +218,15 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st IdentitiesOnly yes IdentityFile="%s" `, workspaceName, workspaceName, binPath, workspaceName, privateKeyFilepath) + + if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { + host += ` ControlMaster auto + ControlPath ~/.ssh/.connection-%r@%h:%p + ControlPersist 600 +` + } + + return host } return fmt.Sprintf( From cffb6fdbae8640a52edd1a44856015db646abd3e Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 7 Jul 2021 20:57:55 +0000 Subject: [PATCH 2/2] Fix listen disconnect --- wsnet/listen.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsnet/listen.go b/wsnet/listen.go index 3a6735f0..3c7c3b3e 100644 --- a/wsnet/listen.go +++ b/wsnet/listen.go @@ -332,10 +332,10 @@ func (l *listener) handle(msg BrokerMessage) func(dc *webrtc.DataChannel) { rw: rw, } co.init() - defer co.Close() defer nc.Close() - + defer co.Close() go func() { + defer dc.Close() _, _ = io.Copy(co, nc) }() _, _ = io.Copy(nc, co)