From 6a1a871dda4a42d096cdb641c9aa4d4a434ebc7c Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Tue, 6 Jan 2015 18:01:11 +0100 Subject: [PATCH] Lock snapshot collection before sorting --- api/snapshot.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/snapshot.go b/api/snapshot.go index fa1a5fc7..ae39bbab 100644 --- a/api/snapshot.go +++ b/api/snapshot.go @@ -13,7 +13,12 @@ func apiSnapshotsList(c *gin.Context) { SortMethodString := c.Request.URL.Query().Get("sort") collection := context.CollectionFactory().SnapshotCollection() - collection.Sort(SortMethodString) + collection.RLock() + defer collection.RUnlock() + + if SortMethodString != "" { + collection.Sort(SortMethodString) + } result := []*deb.Snapshot{} collection.ForEach(func(snapshot *deb.Snapshot) error {