Skip to content

Commit 0b72aea

Browse files
dshulyakmandrigin
authored andcommitted
Ensure that all discovery compoenents are set to nil on stop (#1351)
Previously we always tried to stop discovery if it was enabled according to configuration. Now we check if it was started, because it can be started separataly from a node.
1 parent b394e91 commit 0b72aea

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

api/backend_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,19 @@ func TestCallRPCWithStoppedNode(t *testing.T) {
320320
}
321321

322322
// TODO(adam): add concurrent tests for: SendTransaction
323+
324+
func TestStartStopMultipleTimes(t *testing.T) {
325+
backend := NewStatusBackend()
326+
config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
327+
require.NoError(t, err)
328+
config.NoDiscovery = false
329+
// doesn't have to be running. just any valid enode to bypass validation.
330+
config.ClusterConfig.BootNodes = []string{
331+
"enode://e8a7c03b58911e98bbd66accb2a55d57683f35b23bf9dfca89e5e244eb5cc3f25018b4112db507faca34fb69ffb44b362f79eda97a669a8df29c72e654416784@0.0.0.0:30404",
332+
}
333+
require.NoError(t, err)
334+
require.NoError(t, backend.StartNode(config))
335+
require.NoError(t, backend.StopNode())
336+
require.NoError(t, backend.StartNode(config))
337+
require.NoError(t, backend.StopNode())
338+
}

node/status_node.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,13 @@ func (n *StatusNode) Stop() error {
335335

336336
// stop will stop current StatusNode. A stopped node cannot be resumed.
337337
func (n *StatusNode) stop() error {
338-
if n.discoveryEnabled() {
338+
if n.isDiscoveryRunning() {
339339
if err := n.stopDiscovery(); err != nil {
340-
n.log.Error("Error stopping the PeerPool", "error", err)
340+
n.log.Error("Error stopping the discovery components", "error", err)
341341
}
342342
n.register = nil
343343
n.peerPool = nil
344+
n.discovery = nil
344345
}
345346

346347
if err := n.gethNode.Stop(); err != nil {

0 commit comments

Comments
 (0)