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

use fx lifecycle hooks to start and stop services #1876

Open
marten-seemann opened this issue Nov 11, 2022 · 0 comments
Open

use fx lifecycle hooks to start and stop services #1876

marten-seemann opened this issue Nov 11, 2022 · 0 comments
Labels
effort/days Estimated to take multiple days, but less than a week exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature

Comments

@marten-seemann
Copy link
Contributor

Starting and stopping services on the host has long been a pain point. By using fx's lifecycle hooks we could potentially dramatically simplify our code base.

This is the Close logic in the BasicHost:

func (h *BasicHost) Close() error {
h.closeSync.Do(func() {
h.ctxCancel()
if h.natmgr != nil {
h.natmgr.Close()
}
if h.cmgr != nil {
h.cmgr.Close()
}
if h.ids != nil {
h.ids.Close()
}
if h.autoNat != nil {
h.autoNat.Close()
}
if h.relayManager != nil {
h.relayManager.Close()
}
if h.hps != nil {
h.hps.Close()
}
_ = h.emitters.evtLocalProtocolsUpdated.Close()
_ = h.emitters.evtLocalAddrsUpdated.Close()
h.Network().Close()
h.psManager.Close()
if h.Peerstore() != nil {
h.Peerstore().Close()
}
h.refCount.Wait()
if h.Network().ResourceManager() != nil {
h.Network().ResourceManager().Close()
}
})
return nil
}

There also exist wrapped hosts only for hooking into the Close method, for example here:

type AutoRelayHost struct {
host.Host
ar *AutoRelay
}
func (h *AutoRelayHost) Close() error {
_ = h.ar.Close()
return h.Host.Close()
}

@marten-seemann marten-seemann added kind/enhancement A net-new feature or improvement to an existing feature exp/expert Having worked on the specific codebase is important effort/days Estimated to take multiple days, but less than a week labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/days Estimated to take multiple days, but less than a week exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant