Skip to content

Commit

Permalink
ensure check alive loop always breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ferama committed Apr 25, 2024
1 parent ce59721 commit 22b7212
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/sshd/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,20 @@ func (r *requestHandler) handleRequests() {
func (r *requestHandler) checkAlive(sshConn *ssh.ServerConn, ln net.Listener, addr string) {
ticker := time.NewTicker(r.forwardsKeepAliveInterval)

defer func() {
ln.Close()
r.forwardsMu.Lock()
delete(r.forwards, addr)
r.forwardsMu.Unlock()
}()

log.Println("starting check for forward availability")
for {
<-ticker.C
_, _, err := sshConn.SendRequest("checkalive@rospo", true, nil)
if err != nil {
log.Printf("forward endpoint not available anymore. Closing socket %s", ln.Addr())
ln.Close()
r.forwardsMu.Lock()
delete(r.forwards, addr)
r.forwardsMu.Unlock()
return
break
}
}
}

0 comments on commit 22b7212

Please sign in to comment.