Skip to content

Commit 3485300

Browse files
authored
fix(coderd): Ensure agent disconnect happens after timeout (coder#6600)
Fixes coder#6598
1 parent 7587850 commit 3485300

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

coderd/coderd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func New(options *Options) *API {
175175
if options.AgentInactiveDisconnectTimeout == 0 {
176176
// Multiply the update by two to allow for some lag-time.
177177
options.AgentInactiveDisconnectTimeout = options.AgentConnectionUpdateFrequency * 2
178+
// Set a minimum timeout to avoid disconnecting too soon.
179+
if options.AgentInactiveDisconnectTimeout < 2*time.Second {
180+
options.AgentInactiveDisconnectTimeout = 2 * time.Second
181+
}
178182
}
179183
if options.AgentStatsRefreshInterval == 0 {
180184
options.AgentStatsRefreshInterval = 5 * time.Minute

coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
615615

616616
// We use a custom heartbeat routine here instead of `httpapi.Heartbeat`
617617
// because we want to log the agent's last ping time.
618-
var lastPing time.Time
618+
lastPing := time.Now() // Since the agent initiated the request, assume it's alive.
619619
var pingMu sync.Mutex
620620
go pprof.Do(ctx, pprof.Labels("agent", workspaceAgent.ID.String()), func(ctx context.Context) {
621621
// TODO(mafredri): Is this too frequent? Use separate ping disconnect timeout?

scaletest/reconnectingpty/run_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
func Test_Runner(t *testing.T) {
2525
t.Parallel()
26-
t.Skip("https://github.com/coder/coder/issues/6598")
2726

2827
t.Run("OK", func(t *testing.T) {
2928
t.Parallel()

0 commit comments

Comments
 (0)