From 6233ddf9d19b51f69c0c4a796d88732d1700e585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 16 Nov 2017 11:59:45 +0100 Subject: [PATCH] tpl/partials: Fix the lock contention in cached partial Fixes #4086 --- tpl/partials/partials.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tpl/partials/partials.go b/tpl/partials/partials.go index d999041be16..beb09f426bc 100644 --- a/tpl/partials/partials.go +++ b/tpl/partials/partials.go @@ -120,19 +120,17 @@ func (ns *Namespace) getOrCreate(key, name string, context interface{}) (interfa return p, nil } - ns.cachedPartials.Lock() - defer ns.cachedPartials.Unlock() - - // Double-check. - if p, ok = ns.cachedPartials.p[key]; ok { - return p, nil - } - p, err := ns.Include(name, context) if err != nil { return nil, err } + ns.cachedPartials.Lock() + defer ns.cachedPartials.Unlock() + // Double-check. + if p2, ok := ns.cachedPartials.p[key]; ok { + return p2, nil + } ns.cachedPartials.p[key] = p return p, nil