-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ssh keep alive to ssh tunnel to workspace
- Loading branch information
1 parent
8f2b433
commit 31416db
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,8 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config, | |
// Traffic is coming in from the outside, we need to forward it to the container | ||
if cmd.Proxy || cmd.Stdio { | ||
if cmd.Proxy { | ||
go startSSHKeepAlive(ctx, containerClient, log) | ||
|
||
go func() { | ||
if err := cmd.startRunnerServices(ctx, devPodConfig, containerClient, log); err != nil { | ||
log.Error(err) | ||
|
@@ -451,6 +453,7 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config, | |
!cmd.Proxy && cmd.AgentForwarding && | ||
devPodConfig.ContextOption(config.ContextOptionSSHAgentForwarding) == "true", | ||
func(ctx context.Context, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { | ||
go startSSHKeepAlive(ctx, containerClient, log) | ||
return devssh.Run(ctx, containerClient, command, stdin, stdout, stderr, envVars) | ||
}, | ||
writer, | ||
|
@@ -659,3 +662,21 @@ func preparePipes() (io.Reader, io.WriteCloser, io.Reader, io.WriteCloser, error | |
|
||
return stdoutReader, stdoutWriter, stdinReader, stdinWriter, nil | ||
} | ||
|
||
func startSSHKeepAlive(ctx context.Context, client *ssh.Client, log log.Logger) { | ||
ticker := time.NewTicker(55 * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
log.Infof("SSH keepalive routine stopped: %v", ctx.Err()) | ||
return | ||
case <-ticker.C: | ||
_, _, err := client.SendRequest("[email protected]", true, nil) | ||
if err != nil { | ||
log.Errorf("Failed to send keepalive: %w", err) | ||
} | ||
} | ||
} | ||
} |