diff options
author | Janoš Guljaš <janos@users.noreply.github.com> | 2019-02-07 18:40:36 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-02-07 18:40:36 +0800 |
commit | 26aea736736dc70257b1c11676f626ab775e9339 (patch) | |
tree | 93d60a587905e6f5ac170d71fb0c78127ec75d27 /cmd/geth | |
parent | 81801ccc2b5444ebcf05bf1cf1562fc7a7c2b93e (diff) | |
download | go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar.gz go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar.bz2 go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar.lz go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar.xz go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.tar.zst go-tangerine-26aea736736dc70257b1c11676f626ab775e9339.zip |
cmd, node, p2p/simulations: fix node account manager leak (#19004)
* node: close AccountsManager in new Close method
* p2p/simulations, p2p/simulations/adapters: handle node close on shutdown
* node: move node ephemeralKeystore cleanup to stop method
* node: call Stop in Node.Close method
* cmd/geth: close node.Node created with makeFullNode in cli commands
* node: close Node instances in tests
* cmd/geth, node: minor code style fixes
* cmd, console, miner, mobile: proper node Close() termination
Diffstat (limited to 'cmd/geth')
-rw-r--r-- | cmd/geth/chaincmd.go | 19 | ||||
-rw-r--r-- | cmd/geth/consolecmd.go | 4 | ||||
-rw-r--r-- | cmd/geth/main.go | 1 |
3 files changed, 19 insertions, 5 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 562c7e0de..6d41261f8 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -190,6 +190,8 @@ func initGenesis(ctx *cli.Context) error { } // Open an initialise both full and light databases stack := makeFullNode(ctx) + defer stack.Close() + for _, name := range []string{"chaindata", "lightchaindata"} { chaindb, err := stack.OpenDatabase(name, 0, 0) if err != nil { @@ -209,6 +211,8 @@ func importChain(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } stack := makeFullNode(ctx) + defer stack.Close() + chain, chainDb := utils.MakeChain(ctx, stack) defer chainDb.Close() @@ -303,6 +307,8 @@ func exportChain(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } stack := makeFullNode(ctx) + defer stack.Close() + chain, _ := utils.MakeChain(ctx, stack) start := time.Now() @@ -336,9 +342,11 @@ func importPreimages(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } stack := makeFullNode(ctx) - diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) + defer stack.Close() + diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) start := time.Now() + if err := utils.ImportPreimages(diskdb, ctx.Args().First()); err != nil { utils.Fatalf("Import error: %v\n", err) } @@ -352,9 +360,11 @@ func exportPreimages(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } stack := makeFullNode(ctx) - diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) + defer stack.Close() + diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) start := time.Now() + if err := utils.ExportPreimages(diskdb, ctx.Args().First()); err != nil { utils.Fatalf("Export error: %v\n", err) } @@ -369,8 +379,9 @@ 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 stack.Close() + chain, chainDb := utils.MakeChain(ctx, stack) syncmode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode) dl := downloader.New(syncmode, chainDb, new(event.TypeMux), chain, nil, nil) @@ -441,6 +452,8 @@ func removeDB(ctx *cli.Context) error { func dump(ctx *cli.Context) error { stack := makeFullNode(ctx) + defer stack.Close() + chain, chainDb := utils.MakeChain(ctx, stack) for _, arg := range ctx.Args() { var block *types.Block diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 2500a969c..d4443b328 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -79,7 +79,7 @@ func localConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags node := makeFullNode(ctx) startNode(ctx, node) - defer node.Stop() + defer node.Close() // Attach to the newly started node and start the JavaScript console client, err := node.Attach() @@ -180,7 +180,7 @@ func ephemeralConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags node := makeFullNode(ctx) startNode(ctx, node) - defer node.Stop() + defer node.Close() // Attach to the newly started node and start the JavaScript console client, err := node.Attach() diff --git a/cmd/geth/main.go b/cmd/geth/main.go index dca02c82e..17bf438e2 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -279,6 +279,7 @@ func geth(ctx *cli.Context) error { return fmt.Errorf("invalid command: %q", args[0]) } node := makeFullNode(ctx) + defer node.Close() startNode(ctx, node) node.Wait() return nil |