From 90690ff3972a4191c931521ac243315c142eb202 Mon Sep 17 00:00:00 2001 From: D4VID Date: Thu, 27 Feb 2025 14:21:01 +0100 Subject: [PATCH] Fix crash when ending cluster is not found - has no route to it --- .../src/server/tool/ServerPathTracer.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs index 04caafb..559fbbd 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs @@ -57,6 +57,7 @@ namespace CriticalPathAnalyzer.Server.Tool { var clusterNodes = new List(); var clusterToNodeMapping = new Dictionary(); // Cluster / index of node var queue = new Queue(); + var loopingNodes = new HashSet(); // An input peg, only has a single cluster. // An output peg however can be connected to multiple clusters. @@ -125,6 +126,8 @@ namespace CriticalPathAnalyzer.Server.Tool { // only add the link, don't propagate if (!nextNode.PrevNodeIndexes.Add(node.Index)) { logger.Warn("Loop detected"); + loopingNodes.Add(node.Index); + loopingNodes.Add(nextNode.Index); // already been here - there is a cycle continue; } @@ -161,13 +164,22 @@ namespace CriticalPathAnalyzer.Server.Tool { } } + // Attempt to get the critical path length + // If the ending cluster has not been found, return -1 + Cluster endingCluster = endingClusters.First(); + int criticalPathLength = -1; + if (clusterToNodeMapping.TryGetValue(endingCluster, out int nodeIndex)) { + criticalPathLength = clusterNodes[nodeIndex].Time; + } + // Collect information about each cluster: response = new AnalyzePathResponse() { RequestGuid = requestGuid, Clusters = clusterNodes.SelectMany(node => node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), - CriticalPathLength = clusterNodes[clusterToNodeMapping[endingClusters.First()]].Time, - + CriticalPathLength = criticalPathLength, + LoopingClusters = loopingNodes.SelectMany(loopingNodeIndex => clusterNodes[loopingNodeIndex].Clusters + .Select(cluster => CollectClusterInformation(cluster, 0))).ToList(), // PerimeterComponents = perimeterComponents.ToList(), // NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), };