use Fx to start and stop the host, swarm, autorelay and quicreuse
Fixes #2117. Part of #1993. Part of #2514.
Thanks for removing AutoRelayHost 🎉
I've added a dangling goroutine test which should be sufficient. It implicitly asserts that the connection manager is closed as the connection manager launches a background goroutine. Ideally we'd have some way to also assert that there are no scheduled timers, but I don't think we can.
When doing that, I noticed two issues:
- #2743.
- We don't shut anything down if we fail to start. But, IMO, that's not something to solve in this patch.
(I'm trying to push this forward because I don't want it to develop a bunch of merge conflicts)
Thanks @Stebalien! I didn't know about uber/goleak. Looks helpful. I'll try to fix the current leaks.
Hm. That goroutine should have been excluded...
Oh, different nat goroutine.
I'd add github.com/jackpal/go-nat-pmp.(*Client).GetExternalAddress to the exclusion list.
A test that asserts the connmanager is closed after we close the host/swarm.
This is effectively covered by checking for dangling goroutines.