From 241b7483ea954653512d4895ad6bacf79ee26ddc Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Sat, 16 Jan 2021 23:05:58 -0600 Subject: [PATCH] tpl: Fix race condition in text template baseof Copy most of the htmltemplate cloning to the textemplate implementation in the same function. --- tpl/tplimpl/template.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index eb91ab837ac..60e3b7df93f 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -598,10 +598,16 @@ func (t *templateHandler) applyBaseTemplate(overlay, base templateInfo) (tpl.Tem } } - templ, err = templ.Parse(overlay.template) + templ, err = texttemplate.Must(templ.Clone()).Parse(overlay.template) if err != nil { return nil, overlay.errWithFileContext("parse failed", err) } + + // The extra lookup is a workaround, see + // * https://github.com/golang/go/issues/16101 + // * https://github.com/gohugoio/hugo/issues/2549 + // templ = templ.Lookup(templ.Name()) + return templ, nil }