Skip to content

Commit

Permalink
fix: Close dangling SSH connections on memory
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed May 23, 2023
1 parent 5e07cc5 commit 994f47f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/bridge/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func Clean() {
case <-ch:
return
default:
_, _, err := tunnel.SshClient.SendRequest("keepalive@liman.dev", true, nil)
_, _, err := tunnel.SshClient.SendRequest("keepalive@openssh.com", true, nil)
if err != nil {
tunnel.SshClient.Close()
closeTunnel(tunnel, key)
logger.Sugar().Warnw("error when sending request")
}
Expand Down
10 changes: 8 additions & 2 deletions internal/bridge/ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (t *Tunnel) Start() {
func (t *Tunnel) Stop() {
t.Started = false
t.log.Infow("collapsed tunnel", "details", t)
t.SshClient.Conn.Close()
t.SshClient.Close()
t.cancel()
}

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

<-ctx.Done()
return
select {
case <-ctx.Done():
return
case <-time.After(30 * time.Second):
fmt.Printf("(%v) retrying...\n", t)
}
}
}

Expand Down

0 comments on commit 994f47f

Please sign in to comment.