From 8a65ef627d849e36ea8ecbf3631fbd767c43b485 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 18 Aug 2021 16:56:05 +1000 Subject: [PATCH] Set direct sqlite storage conn to nil on close This might help catch the reason for SQLITE_MISUSE in getCapacity. --- storage/sqlite/direct.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/storage/sqlite/direct.go b/storage/sqlite/direct.go index 899cf1af..5e6b52dd 100644 --- a/storage/sqlite/direct.go +++ b/storage/sqlite/direct.go @@ -114,15 +114,19 @@ func (c *client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (stora return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil } -func (c *client) Close() error { +func (c *client) Close() (err error) { c.l.Lock() defer c.l.Unlock() c.flushBlobs() - c.closed = true if c.opts.BlobFlushInterval != 0 { c.blobFlusher.Stop() } - return c.conn.Close() + if !c.closed { + c.closed = true + err = c.conn.Close() + c.conn = nil + } + return } type torrent struct {