Skip to content

Commit a3be26f

Browse files
committed
client: stop leaking "keep-alive" go-routine
When keep-alive is enabled, Client.loop() creates a go-routine to provide the functionality, however, the go-routine never exits, not even when the client's SSH connection to the server has been torn down, thus leaking the go-routine. This typically isn't a problem for the command-line chisel client since it is single-use; the SSH connection is torn down only when the client is terminating anyway. However, such a go-routine leak could become problematic if the client ever learns to manage multiple SSH connections (perhaps, say, via an interactive mode) or when chisel is used as a library by some other program which manages multiple connections. Therefore, ensure that the go-routine terminates when the SSH connection is torn down.
1 parent 7cfb8e4 commit a3be26f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func (c *Client) loop() {
149149
for range time.Tick(c.config.KeepAlive) {
150150
if c.sshConn != nil {
151151
c.sshConn.SendRequest("ping", true, nil)
152+
} else {
153+
break
152154
}
153155
}
154156
}()

0 commit comments

Comments
 (0)