From f130b9a40136ce808236d7c704fc0abfd69a4687 Mon Sep 17 00:00:00 2001 From: Nate Sales Date: Wed, 4 Sep 2024 17:40:13 -0400 Subject: [PATCH] fix(templating): data race in array append --- pkg/templating/templating.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/templating/templating.go b/pkg/templating/templating.go index 1c113cdb..0ac52619 100644 --- a/pkg/templating/templating.go +++ b/pkg/templating/templating.go @@ -192,6 +192,9 @@ var funcMap = template.FuncMap{ // UniqueProtocolName takes a protocol-safe string and address family and returns a unique protocol name "UniqueProtocolName": func(s, userSuppliedName *string, af string, asn *int, tags *[]string) string { + protocolNameMapLock.Lock() + defer protocolNameMapLock.Unlock() + protoName := fmt.Sprintf("%s_AS%d_v%s", *s, *asn, af) i := 1 for { @@ -201,12 +204,10 @@ var funcMap = template.FuncMap{ if tags != nil { t = *tags } - protocolNameMapLock.Lock() protocolNameMap[protoName] = &Protocol{ Name: *userSuppliedName, Tags: t, } - protocolNameMapLock.Unlock() return protoName } protoName = fmt.Sprintf("%s_AS%d_v%s_%d", *s, *asn, af, i)