From 270f1d0d4bf2e0258dcf25b4d74655fa51f5f64d Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Tue, 30 Jan 2024 18:10:58 +0000 Subject: [PATCH] fix: add timeout to listening ports request This can potentially hang for 15m if the agent is unreachable. --- coderd/workspaceagents.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index d438d6663d161..d65fca2cf93dc 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -762,6 +762,11 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req ctx := r.Context() workspaceAgent := httpmw.WorkspaceAgentParam(r) + // If the agent is unreachable, the request will hang. Assume that if we + // don't get a response after 30s that the agent is unreachable. + ctx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + apiAgent, err := db2sdk.WorkspaceAgent( api.DERPMap(), *api.TailnetCoordinator.Load(), workspaceAgent, nil, nil, nil, api.AgentInactiveDisconnectTimeout, api.DeploymentValues.AgentFallbackTroubleshootingURL.String(),