Skip to content

Commit 270f1d0

Browse files
committed
fix: add timeout to listening ports request
This can potentially hang for 15m if the agent is unreachable.
1 parent 73a6899 commit 270f1d0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

coderd/workspaceagents.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
762762
ctx := r.Context()
763763
workspaceAgent := httpmw.WorkspaceAgentParam(r)
764764

765+
// If the agent is unreachable, the request will hang. Assume that if we
766+
// don't get a response after 30s that the agent is unreachable.
767+
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
768+
defer cancel()
769+
765770
apiAgent, err := db2sdk.WorkspaceAgent(
766771
api.DERPMap(), *api.TailnetCoordinator.Load(), workspaceAgent, nil, nil, nil, api.AgentInactiveDisconnectTimeout,
767772
api.DeploymentValues.AgentFallbackTroubleshootingURL.String(),

0 commit comments

Comments
 (0)