diff --git a/swarm/storage/localstore/gc_test.go b/swarm/storage/localstore/gc_test.go index a009fd570f..9f5f497669 100644 --- a/swarm/storage/localstore/gc_test.go +++ b/swarm/storage/localstore/gc_test.go @@ -278,7 +278,12 @@ func TestDB_gcSize(t *testing.T) { } } - err = db.Close() + // DB.Close writes gc size to disk, so + // Instead calling Close, simulate database shutdown + // without it. + close(db.close) + db.updateGCWG.Wait() + err = db.shed.Close() if err != nil { t.Fatal(err) } diff --git a/swarm/storage/localstore/localstore.go b/swarm/storage/localstore/localstore.go index ae095f7e2f..158bf4a437 100644 --- a/swarm/storage/localstore/localstore.go +++ b/swarm/storage/localstore/localstore.go @@ -21,8 +21,10 @@ import ( "encoding/hex" "errors" "sync" + "sync/atomic" "time" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/swarm/shed" "github.com/ethereum/go-ethereum/swarm/storage" "github.com/ethereum/go-ethereum/swarm/storage/mock" @@ -344,6 +346,9 @@ func New(path string, baseKey []byte, o *Options) (db *DB, err error) { func (db *DB) Close() (err error) { close(db.close) db.updateGCWG.Wait() + if err := db.writeGCSize(atomic.LoadInt64(&db.gcSize)); err != nil { + log.Error("localstore: write gc size", "err", err) + } return db.shed.Close() }