Skip to content

Commit

Permalink
return and log dht.Close() error
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Jun 25, 2024
1 parent 273018b commit 26d8426
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions network/p2p/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ func (c *CapabilitiesDiscovery) FindPeers(ctx context.Context, ns string, opts .
}

// Close should be called when fully shutting down the node
func (c *CapabilitiesDiscovery) Close() {
_ = c.dht.Close()
func (c *CapabilitiesDiscovery) Close() error {
err := c.dht.Close()
c.wg.Wait()
return err
}

// Host exposes the underlying libp2p host.Host object
Expand Down
6 changes: 4 additions & 2 deletions network/p2p/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ func TestCapabilities_Varying(t *testing.T) {
wg.Wait()

for _, disc := range capsDisc[3:] {
disc.Close()
err := disc.Close()
require.NoError(t, err)
// Make sure it actually closes
disc.wg.Wait()
}
Expand Down Expand Up @@ -347,6 +348,7 @@ func TestCapabilities_ExcludesSelf(t *testing.T) {
"Found self when searching for capability",
)

disc[0].Close()
err := disc[0].Close()
require.NoError(t, err)
disc[0].wg.Wait()
}
5 changes: 4 additions & 1 deletion network/p2pNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ func (n *P2PNetwork) Start() error {
// Stop closes sockets and stop threads.
func (n *P2PNetwork) Stop() {
if n.capabilitiesDiscovery != nil {
n.capabilitiesDiscovery.Close()
err := n.capabilitiesDiscovery.Close()
if err != nil {
n.log.Warnf("Error closing capabilities discovery: %v", err)

Check warning on line 370 in network/p2pNetwork.go

View check run for this annotation

Codecov / codecov/patch

network/p2pNetwork.go#L370

Added line #L370 was not covered by tests
}
}

n.handler.ClearHandlers([]Tag{})
Expand Down

0 comments on commit 26d8426

Please sign in to comment.