Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close peerstore and document Host Close #1037

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only correct order to call these actions? What happens if we call Close before we cancel the context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raulk The order is NOT important. I've updated the PR.

// Canceling the passed context followed by calling `Close` on the returned Host will stop the returned libp2p node.
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