From 0dcb8c02c282d628169d7a02860a46b2c67f76a2 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 3 Sep 2024 15:31:28 -0400 Subject: [PATCH] hcl2template: don't use Walk for walking on DAG Walk uses a reverse topological order to walk on the graph, doing that visit concurrently if possible. This is nice as we can speed-up execution of datasources and locals, however since the `Variables` map stored in the config, and the production of the context for it, are not meant to be used concurrently, this means that we end-up in cases where Packer crashes because of concurrent accesses to that map. So until we can change this behaviour, we will fallback to using the sequential visit algorithm for those vertexes, therefore limiting the risk of those conflicts. --- hcl2template/parser.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hcl2template/parser.go b/hcl2template/parser.go index 5c1460419..5a7fb315b 100644 --- a/hcl2template/parser.go +++ b/hcl2template/parser.go @@ -461,11 +461,6 @@ func (cfg *PackerConfig) evaluateBuildPrereqs(skipDatasources bool) hcl.Diagnost }) } - // ("unsupported node of type %q") - if diags.HasErrors() { - return diags - } - return nil } @@ -473,7 +468,15 @@ func (cfg *PackerConfig) evaluateBuildPrereqs(skipDatasources bool) hcl.Diagnost cfg.LocalVariables = Variables{} } - return diags.Extend(graph.Walk(walkFunc)) + for _, vtx := range graph.ReverseTopologicalOrder() { + vtxDiags := walkFunc(vtx) + if vtxDiags.HasErrors() { + diags = diags.Extend(vtxDiags) + return diags + } + } + + return nil } func (cfg *PackerConfig) Initialize(opts packer.InitializeOptions) hcl.Diagnostics {