Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Why manager's constructor does not receive context? #49

Closed
Wondertan opened this issue Jun 13, 2019 · 3 comments · Fixed by libp2p/go-libp2p#656
Closed

Why manager's constructor does not receive context? #49

Wondertan opened this issue Jun 13, 2019 · 3 comments · Fixed by libp2p/go-libp2p#656

Comments

@Wondertan
Copy link

Libp2p uses contexts extensively and nearly every component has a context as first parameter in their constructors, except connection manager, it just creates a new by Background(). I am almost sure this is not done by mistake, so the question is why? What if I want to handle closing by canceling context?

@Wondertan
Copy link
Author

The issue also forces BasicHost with custom manager to be only closed by Close(), otherwise manager won't be closed and may leak

@Stebalien
Copy link
Member

Services should be called by calling Close.

In the past, we used contexts for closing services but contexts don't allow orderly shutdown, they just abort everything all at once. This is especially problematic when, for example, a database needs to be closed after all services using it.

However, the fact that the connection manager isn't getting closed when the context is canceled is a bug: libp2p/go-libp2p#656.

@Wondertan
Copy link
Author

Thanks for explanation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants