Skip to content

Commit

Permalink
tpl/partials: Fix the lock contention in cached partial
Browse files Browse the repository at this point in the history
Fixes #4086
  • Loading branch information
bep committed Nov 16, 2017
1 parent e66d813 commit 6233ddf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tpl/partials/partials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6233ddf

Please sign in to comment.