Skip to content

Commit 994f47f

Browse files
committed
fix: Close dangling SSH connections on memory
1 parent 5e07cc5 commit 994f47f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

internal/bridge/clean.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ func Clean() {
8888
case <-ch:
8989
return
9090
default:
91-
_, _, err := tunnel.SshClient.SendRequest("keepalive@liman.dev", true, nil)
91+
_, _, err := tunnel.SshClient.SendRequest("keepalive@openssh.com", true, nil)
9292
if err != nil {
93+
tunnel.SshClient.Close()
9394
closeTunnel(tunnel, key)
9495
logger.Sugar().Warnw("error when sending request")
9596
}

internal/bridge/ssh_tunnel.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func (t *Tunnel) Start() {
5555
func (t *Tunnel) Stop() {
5656
t.Started = false
5757
t.log.Infow("collapsed tunnel", "details", t)
58+
t.SshClient.Conn.Close()
59+
t.SshClient.Close()
5860
t.cancel()
5961
}
6062

@@ -155,8 +157,12 @@ func (t *Tunnel) bindTunnel(ctx context.Context, wg *sync.WaitGroup) {
155157
}
156158
}()
157159

158-
<-ctx.Done()
159-
return
160+
select {
161+
case <-ctx.Done():
162+
return
163+
case <-time.After(30 * time.Second):
164+
fmt.Printf("(%v) retrying...\n", t)
165+
}
160166
}
161167
}
162168

0 commit comments

Comments
 (0)