From 7ad921758ddf66fb031b5504c6b945e1260372da Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 3 Oct 2022 14:47:01 +0000 Subject: [PATCH] fix: Add isFirst check before err check This was causing TestBlockNonBrowser to hang and fail. --- codersdk/workspaceagents.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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) })