fix: Add isFirst check before err check (#4326)

This was causing TestBlockNonBrowser to hang and fail.
This commit is contained in:
Kyle Carberry
2022-10-03 09:51:20 -05:00
committed by GitHub
parent c7aea2fc42
commit 88d49dbcab
+8 -8
View File
@@ -331,6 +331,14 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg
// Need to disable compression to avoid a data-race.
CompressionMode: websocket.CompressionDisabled,
})
if isFirst {
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
@@ -338,14 +346,6 @@ func (c *Client) DialWorkspaceAgentTailnet(ctx context.Context, logger slog.Logg
logger.Debug(ctx, "failed to dial", slog.Error(err))
continue
}
if isFirst {
if res.StatusCode == http.StatusConflict {
first <- readBodyAsError(res)
return
}
isFirst = false
close(first)
}
sendNode, errChan := tailnet.ServeCoordinator(websocket.NetConn(ctx, ws, websocket.MessageBinary), func(node []*tailnet.Node) error {
return conn.UpdateNodes(node)
})