diff --git a/codersdk/workspaceagents.go b/codersdk/workspaceagents.go index 687aa704e663b..6979aaf46bd71 100644 --- a/codersdk/workspaceagents.go +++ b/codersdk/workspaceagents.go @@ -331,21 +331,21 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg // Need to disable compression to avoid a data-race. CompressionMode: websocket.CompressionDisabled, }) - if err != nil { - if errors.Is(err, context.Canceled) { - return - } - logger.Debug(ctx, "failed to dial", slog.Error(err)) - continue - } if isFirst { - if res.StatusCode == http.StatusConflict { + if err != nil && res.StatusCode == http.StatusConflict { first <- readBodyAsError(res) return } isFirst = false close(first) } + if err != nil { + if errors.Is(err, context.Canceled) { + return + } + logger.Debug(ctx, "failed to dial", slog.Error(err)) + continue + } sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(node []*tailnet.Node) error { return conn.UpdateNodes(node) })