From 27f3b7a81480269a55877ade0c6aee975d742606 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Tue, 30 Jan 2024 13:53:52 -0600 Subject: [PATCH] fix: add timeout to listening ports request (#11935) 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 29c15056b4..52cacd57cc 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -722,6 +722,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(),