]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix race in sqlite direct storage init v1.30.0
authorMatt Joiner <anacrolix@gmail.com>
Tue, 10 Aug 2021 23:43:40 +0000 (09:43 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 10 Aug 2021 23:44:09 +0000 (09:44 +1000)
There's a race between starting the blob flusher and assigning the timer to the storage client.

storage/sqlite/direct.go

index 7748f92182780789be65f590c9389d119cbd91c3..899cf1af3dd2646f46152c68b048e1a940650594 100644 (file)
@@ -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)
        }