Skip to content

Commit

Permalink
Close peerstore and document Host Close (#1037)
Browse files Browse the repository at this point in the history
* close peerstore and docs change

* update docs
  • Loading branch information
aarshkshah1992 committed Jan 19, 2021
1 parent 1c850e1 commit 890f2e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ChainOptions(opts ...Option) Option {
// - If no peerstore is provided, the host is initialized with an empty
// peerstore.
//
// Canceling the passed context will stop the returned libp2p node.
// To stop/shutdown the returned libp2p node, the user needs to cancel the passed context and call `Close` on the returned Host.
func New(ctx context.Context, opts ...Option) (host.Host, error) {
return NewWithoutDefaults(ctx, append(opts, FallbackDefaults)...)
}
Expand Down
4 changes: 4 additions & 0 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ func (h *BasicHost) Close() error {
_ = h.emitters.evtLocalAddrsUpdated.Close()
h.Network().Close()

if h.Peerstore() != nil {
h.Peerstore().Close()
}

h.refCount.Wait()
})

Expand Down

0 comments on commit 890f2e8

Please sign in to comment.