diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index a7c20db773..5e4b77a6a5 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -282,7 +282,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u // close terminates the Ethereum connection and tears down the faucet. func (f *faucet) close() error { - return f.stack.Stop() + return f.stack.Close() } // listenAndServe registers the HTTP handlers for the faucet and boots it up diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 53888b615f..11b51124d0 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -288,6 +288,7 @@ func bzzd(ctx *cli.Context) error { if err != nil { utils.Fatalf("can't create node: %v", err) } + defer stack.Close() //a few steps need to be done after the config phase is completed, //due to overriding behavior @@ -365,6 +366,8 @@ func getPrivKey(ctx *cli.Context) *ecdsa.PrivateKey { if err != nil { utils.Fatalf("can't create node: %v", err) } + defer stack.Close() + return getAccount(bzzconfig.BzzAccount, ctx, stack) } diff --git a/console/console_test.go b/console/console_test.go index 26465ca6f4..55d799725a 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -149,8 +149,8 @@ func (env *tester) Close(t *testing.T) { if err := env.console.Stop(false); err != nil { t.Errorf("failed to stop embedded console: %v", err) } - if err := env.stack.Stop(); err != nil { - t.Errorf("failed to stop embedded node: %v", err) + if err := env.stack.Close(); err != nil { + t.Errorf("failed to tear down embedded node: %v", err) } os.RemoveAll(env.workspace) } diff --git a/miner/stress_clique.go b/miner/stress_clique.go index 7e19975aec..8a355a4dc4 100644 --- a/miner/stress_clique.go +++ b/miner/stress_clique.go @@ -69,7 +69,7 @@ func main() { if err != nil { panic(err) } - defer node.Stop() + defer node.Close() for node.Server().NodeInfo().Ports.Listener == 0 { time.Sleep(250 * time.Millisecond) diff --git a/miner/stress_ethash.go b/miner/stress_ethash.go index 044ca9a218..040af9fba2 100644 --- a/miner/stress_ethash.go +++ b/miner/stress_ethash.go @@ -69,7 +69,7 @@ func main() { if err != nil { panic(err) } - defer node.Stop() + defer node.Close() for node.Server().NodeInfo().Ports.Listener == 0 { time.Sleep(250 * time.Millisecond) diff --git a/mobile/geth.go b/mobile/geth.go index 781f42f708..fba3e5711b 100644 --- a/mobile/geth.go +++ b/mobile/geth.go @@ -192,6 +192,12 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { return &Node{rawStack}, nil } +// Close terminates a running node along with all it's services, tearing internal +// state doen too. It's not possible to restart a closed node. +func (n *Node) Close() error { + return n.node.Close() +} + // Start creates a live P2P node and starts running it. func (n *Node) Start() error { return n.node.Start() diff --git a/node/node_example_test.go b/node/node_example_test.go index 1971d820ae..57b18855f1 100644 --- a/node/node_example_test.go +++ b/node/node_example_test.go @@ -47,6 +47,7 @@ func ExampleService() { log.Fatalf("Failed to create network node: %v", err) } defer stack.Close() + // Create and register a simple network service. This is done through the definition // of a node.ServiceConstructor that will instantiate a node.Service. The reason for // the factory method approach is to support service restarts without relying on the