From 78346372ba0b50785eabea59323b58993b1f0ae4 Mon Sep 17 00:00:00 2001 From: Shihao Xia Date: Wed, 28 Jul 2021 19:36:47 -0400 Subject: [PATCH 1/2] add db close to avoid goroutine leak --- core/rawdb/accessors_chain_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index ea9dc436cfdd..466498e930ed 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -494,6 +494,9 @@ func TestAncientStorage(t *testing.T) { if blob := ReadTdRLP(db, fakeHash, number); len(blob) != 0 { t.Fatalf("invalid td returned") } + if err := db.Close(); err != nil { + t.Fatalf("failed to close database") + } } func TestCanonicalHashIteration(t *testing.T) { From ec266de29085ec540705a04e7e3e5596859a1712 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Sat, 7 Aug 2021 23:12:56 +0200 Subject: [PATCH 2/2] core/rawdb: move close to defer --- core/rawdb/accessors_chain_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index 466498e930ed..f20e8b1fffb5 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -444,6 +444,7 @@ func TestAncientStorage(t *testing.T) { if err != nil { t.Fatalf("failed to create database with ancient backend") } + defer db.Close() // Create a test block block := types.NewBlockWithHeader(&types.Header{ Number: big.NewInt(0), @@ -494,9 +495,6 @@ func TestAncientStorage(t *testing.T) { if blob := ReadTdRLP(db, fakeHash, number); len(blob) != 0 { t.Fatalf("invalid td returned") } - if err := db.Close(); err != nil { - t.Fatalf("failed to close database") - } } func TestCanonicalHashIteration(t *testing.T) {