From 16da133d61d7a1fcde53370e697472fa9837ffbc Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Wed, 17 Nov 2021 17:33:37 +0300 Subject: [PATCH] cli: release resources occupied by chain before `dumpDB` exit Problem: ``` --- FAIL: TestDumpDB (0.08s) --- FAIL: TestDumpDB/too_low_chain testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestDumpDB_too_low_chain357310492\001\chains\privnet\000001.log: The process cannot access the file because it is being used by another process. ``` Solution: Release resources occupied by the chain even on non-error command exit. --- cli/server/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/server/server.go b/cli/server/server.go index 73dc32cfa..1a37ca997 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -186,6 +186,11 @@ func dumpDB(ctx *cli.Context) error { if err != nil { return err } + defer func() { + pprof.ShutDown() + prometheus.ShutDown() + chain.Close() + }() chainCount := chain.BlockHeight() + 1 if start+count > chainCount { @@ -199,9 +204,6 @@ func dumpDB(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err.Error(), 1) } - pprof.ShutDown() - prometheus.ShutDown() - chain.Close() return nil }