From 16101b56fe456163cf36ba463fcec03b36d7755e Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 2 Oct 2015 19:59:47 +0200 Subject: [PATCH] Fix lock handling in cache flusher for API Unlocking the different elements in cache flusher was deferred to the end of the function. Unfortunately, being a for loop wrapped in a goroutine, deferred were never executed. --- api/api.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/api/api.go b/api/api.go index cadaae6d..30bddddf 100644 --- a/api/api.go +++ b/api/api.go @@ -32,25 +32,27 @@ func cacheFlusher() { for { <-ticker - // lock everything to eliminate in-progress calls - r := context.CollectionFactory().RemoteRepoCollection() - r.Lock() - defer r.Unlock() + func() { + // lock everything to eliminate in-progress calls + r := context.CollectionFactory().RemoteRepoCollection() + r.Lock() + defer r.Unlock() - l := context.CollectionFactory().LocalRepoCollection() - l.Lock() - defer l.Unlock() + l := context.CollectionFactory().LocalRepoCollection() + l.Lock() + defer l.Unlock() - s := context.CollectionFactory().SnapshotCollection() - s.Lock() - defer s.Unlock() + s := context.CollectionFactory().SnapshotCollection() + s.Lock() + defer s.Unlock() - p := context.CollectionFactory().PublishedRepoCollection() - p.Lock() - defer p.Unlock() + p := context.CollectionFactory().PublishedRepoCollection() + p.Lock() + defer p.Unlock() - // all collections locked, flush them - context.CollectionFactory().Flush() + // all collections locked, flush them + context.CollectionFactory().Flush() + }() } }