Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 732b0bf

Browse files
authored
chore: Cache SSH connections (#378)
* chore: Cache SSH connections * Fix listen disconnect
1 parent e13b801 commit 732b0bf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

internal/cmd/configssh.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/user"
1010
"path/filepath"
11+
"runtime"
1112
"sort"
1213
"strings"
1314

@@ -208,7 +209,7 @@ func makeNewConfigs(binPath, userName string, workspaces []coderutil.WorkspaceWi
208209

209210
func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath string, tunnel bool) string {
210211
if tunnel {
211-
return fmt.Sprintf(
212+
host := fmt.Sprintf(
212213
`Host coder.%s
213214
HostName coder.%s
214215
ProxyCommand %s tunnel %s 12213 stdio
@@ -217,6 +218,15 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
217218
IdentitiesOnly yes
218219
IdentityFile="%s"
219220
`, workspaceName, workspaceName, binPath, workspaceName, privateKeyFilepath)
221+
222+
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
223+
host += ` ControlMaster auto
224+
ControlPath ~/.ssh/.connection-%r@%h:%p
225+
ControlPersist 600
226+
`
227+
}
228+
229+
return host
220230
}
221231

222232
return fmt.Sprintf(

wsnet/listen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ func (l *listener) handle(msg BrokerMessage) func(dc *webrtc.DataChannel) {
332332
rw: rw,
333333
}
334334
co.init()
335-
defer co.Close()
336335
defer nc.Close()
337-
336+
defer co.Close()
338337
go func() {
338+
defer dc.Close()
339339
_, _ = io.Copy(co, nc)
340340
}()
341341
_, _ = io.Copy(nc, co)

0 commit comments

Comments
 (0)