From 4e1aab11369b67ce7d225a43ac6f5a204d50961a Mon Sep 17 00:00:00 2001 From: mpl Date: Wed, 24 Aug 2016 01:25:54 +0200 Subject: [PATCH] pkg/search: lock index for corpus creation As soon as the (bs->index) sync handler is initialized, it starts writing pending blobs to the index. However, so far the corpus initialization has been left, unguarded, up to the search handler. Which means lots of potential data races on the corpus fields between the sync handler writing a blob to the index, and the search handler creating all the pieces of the corpus itself. This change fixes the issue by locking the index while the search handler is creating the corpus. This change does not entirely fix issue #750, as there seems to be yet another data race going on, but it is related as the fixed race was found thanks to the race trace at: https://github.com/camlistore/camlistore/issues/750#issuecomment-241881987 Change-Id: I6de0165064a4f8934466f6a08710b4962f7b0256 --- pkg/search/handler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/search/handler.go b/pkg/search/handler.go index f1748c52e..a9638b149 100644 --- a/pkg/search/handler.go +++ b/pkg/search/handler.go @@ -146,11 +146,14 @@ func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handl h := NewHandler(indexer, ownerBlobRef) if slurpToMemory { ii := indexer.(*index.Index) + ii.Lock() corpus, err := ii.KeepInMemory() if err != nil { + ii.Unlock() return nil, fmt.Errorf("error slurping index to memory: %v", err) } h.corpus = corpus + ii.Unlock() } return h, nil }