From db999c61776739cf9727210c7ce114ed94029da9 Mon Sep 17 00:00:00 2001 From: Ahsan Barkati Date: Thu, 10 Sep 2020 16:47:49 +0530 Subject: [PATCH 1/2] Fix random output in kshortest path --- query/shortest.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/query/shortest.go b/query/shortest.go index 35505af5e35..200ba21bde2 100644 --- a/query/shortest.go +++ b/query/shortest.go @@ -341,7 +341,10 @@ func runKShortestPaths(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) { } // Add path to list. + itemRoute := make([]pathInfo, len(*item.path.route)) + copy(itemRoute, *item.path.route) newRoute := item.path + newRoute.route = &itemRoute newRoute.totalWeight = item.cost kroutes = append(kroutes, newRoute) if len(kroutes) == numPaths { From 570b4ec098442f3d5c16ee46c62f02acf6811507 Mon Sep 17 00:00:00 2001 From: Ahsan Barkati Date: Mon, 14 Sep 2020 18:06:29 +0530 Subject: [PATCH 2/2] Add comment --- query/shortest.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/query/shortest.go b/query/shortest.go index 200ba21bde2..2ece3c232fc 100644 --- a/query/shortest.go +++ b/query/shortest.go @@ -340,7 +340,9 @@ func runKShortestPaths(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) { continue } - // Add path to list. + // Add path to list after making a copy of the path in itemRoute. A copy of + // *item.path.route is required because it has to be put back in the sync pool and a + // future reuse can alter the item already present in kroute because it is a pointer. itemRoute := make([]pathInfo, len(*item.path.route)) copy(itemRoute, *item.path.route) newRoute := item.path