From 718ad2224b4b60b1a11d3a6f2ca6cc2fbae13f37 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 28 Jan 2014 15:16:06 +0100 Subject: [PATCH] Fix LevelDB closing order. The storage itself should be closed before any of the objects passed into it are closed (otherwise closing the storage can randomly freeze). Defers are executed in reverse order, so closing the storage should be the last of the defer statements. Change-Id: Id920318b876f5b94767ed48c81221b3456770620 --- storage/raw/leveldb/leveldb.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/storage/raw/leveldb/leveldb.go b/storage/raw/leveldb/leveldb.go index f206a4ab4..941c6674f 100644 --- a/storage/raw/leveldb/leveldb.go +++ b/storage/raw/leveldb/leveldb.go @@ -260,12 +260,6 @@ func NewLevelDBPersistence(o LevelDBOptions) (*LevelDBPersistence, error) { func (l *LevelDBPersistence) Close() error { // These are deferred to take advantage of forced closing in case of stack // unwinding due to anomalies. - defer func() { - if l.storage != nil { - l.storage.Close() - } - }() - defer func() { if l.filterPolicy != nil { l.filterPolicy.Close() @@ -296,6 +290,12 @@ func (l *LevelDBPersistence) Close() error { } }() + defer func() { + if l.storage != nil { + l.storage.Close() + } + }() + return nil }