From: Matt Joiner Date: Tue, 10 Aug 2021 23:43:40 +0000 (+1000) Subject: Fix race in sqlite direct storage init X-Git-Tag: v1.30.0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=87294355fb3c18ec0b17b24bdb567840787924b0;p=btrtrc.git Fix race in sqlite direct storage init There's a race between starting the blob flusher and assigning the timer to the storage client. --- 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) }