From 87294355fb3c18ec0b17b24bdb567840787924b0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 11 Aug 2021 09:43:40 +1000 Subject: [PATCH] Fix race in sqlite direct storage init There's a race between starting the blob flusher and assigning the timer to the storage client. --- storage/sqlite/direct.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/sqlite/direct.go b/storage/sqlite/direct.go index 7748f921..899cf1af 100644 --- a/storage/sqlite/direct.go +++ b/storage/sqlite/direct.go @@ -58,6 +58,9 @@ func NewDirectStorage(opts NewDirectStorageOpts) (_ storage.ClientImplCloser, er blobs: make(map[string]*sqlite.Blob), opts: opts, } + // Avoid race with cl.blobFlusherFunc + cl.l.Lock() + defer cl.l.Unlock() if opts.BlobFlushInterval != 0 { cl.blobFlusher = time.AfterFunc(opts.BlobFlushInterval, cl.blobFlusherFunc) }