Skip to content

Commit aa3744d

Browse files
committed
feat: Set default agent timeout to ~72h
1 parent 615450c commit aa3744d

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

agent/agentssh/agentssh.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
105105
metrics: metrics,
106106
}
107107

108-
s.srv = &ssh.Server{
108+
srv := &ssh.Server{
109109
ChannelHandlers: map[string]ssh.ChannelHandler{
110110
"direct-tcpip": ssh.DirectTCPIPHandler,
111111
"direct-streamlocal@openssh.com": directStreamLocalHandler,
@@ -152,6 +152,12 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
152152
MaxTimeout: maxTimeout,
153153
}
154154

155+
if maxTimeout >= 3*time.Minute {
156+
srv.ClientAliveInterval = maxTimeout / 3
157+
srv.ClientAliveCountMax = 3
158+
}
159+
160+
s.srv = srv
155161
return s, nil
156162
}
157163

agent/agentssh/agentssh_internal_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,7 @@ func (testSSHContext) Permissions() *gliderssh.Permissions {
191191
func (testSSHContext) SetValue(_, _ interface{}) {
192192
panic("not implemented")
193193
}
194+
195+
func (testSSHContext) KeepAlive() *gliderssh.SessionKeepAlive {
196+
panic("not implemented")
197+
}

cli/agent.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
323323
Value: clibase.BoolOf(&noReap),
324324
},
325325
{
326-
Flag: "ssh-max-timeout",
327-
Default: "0",
326+
Flag: "ssh-max-timeout",
327+
// tcpip.KeepaliveIdleOption = 72h (forwardTCPSockOpts() in tailnet/conn.go)
328+
Default: fmt.Sprintf("%v", 72*time.Hour-time.Minute),
328329
Env: "CODER_AGENT_SSH_MAX_TIMEOUT",
329330
Description: "Specify the max timeout for a SSH connection.",
330331
Value: clibase.DurationOf(&sshMaxTimeout),

cli/testdata/coder_agent_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Starts the Coder workspace agent.
3030
--prometheus-address string, $CODER_AGENT_PROMETHEUS_ADDRESS (default: 127.0.0.1:2112)
3131
The bind address to serve Prometheus metrics.
3232

33-
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 0)
33+
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 71h59m0s)
3434
Specify the max timeout for a SSH connection.
3535

3636
--tailnet-listen-port int, $CODER_AGENT_TAILNET_LISTEN_PORT (default: 0)

0 commit comments

Comments
 (0)