From d4620798b9bd565d2169913af6b21f35e8a0c9e6 Mon Sep 17 00:00:00 2001 From: wanwiset25 Date: Tue, 5 Mar 2024 15:15:49 +0400 Subject: [PATCH 1/2] Ensure DB Is Closed Before The Client Exit --- cmd/XDC/chaincmd.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index 2f18dae19600..d680af7c06f8 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -319,7 +319,8 @@ func exportChain(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } stack, _ := makeFullNode(ctx) - chain, _ := utils.MakeChain(ctx, stack) + chain, db := utils.MakeChain(ctx, stack) + defer db.Close() start := time.Now() var err error @@ -353,6 +354,7 @@ func importPreimages(ctx *cli.Context) error { } stack, _ := makeFullNode(ctx) diskdb := utils.MakeChainDatabase(ctx, stack) + defer diskdb.Close() start := time.Now() if err := utils.ImportPreimages(diskdb, ctx.Args().First()); err != nil { @@ -369,6 +371,7 @@ func exportPreimages(ctx *cli.Context) error { } stack, _ := makeFullNode(ctx) diskdb := utils.MakeChainDatabase(ctx, stack) + defer diskdb.Close() start := time.Now() if err := utils.ExportPreimages(diskdb, ctx.Args().First()); err != nil { @@ -386,6 +389,7 @@ func copyDb(ctx *cli.Context) error { // Initialize a new chain for the running node to sync into stack, _ := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) + defer chainDb.Close() syncmode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode) dl := downloader.New(syncmode, chainDb, new(event.TypeMux), chain, nil, nil, nil) @@ -458,6 +462,8 @@ func removeDB(ctx *cli.Context) error { func dump(ctx *cli.Context) error { stack, _ := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) + defer chainDb.Close() + for _, arg := range ctx.Args() { var block *types.Block if hashish(arg) { From 0f4141de247c37123130fc2d4e02121c806e29f0 Mon Sep 17 00:00:00 2001 From: wanwiset25 Date: Tue, 5 Mar 2024 18:18:53 +0400 Subject: [PATCH 2/2] remove db.Close() (already done by defer) --- cmd/XDC/chaincmd.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index d680af7c06f8..ae4221e4b211 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -483,7 +483,6 @@ func dump(ctx *cli.Context) error { fmt.Printf("%s\n", state.Dump()) } } - chainDb.Close() return nil }