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.
This commit is contained in:
AnnaShaleva 2021-11-17 17:33:37 +03:00 committed by Anna Shaleva
parent aefb6f9fee
commit 16da133d61

View file

@ -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
}