mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-15 23:06:52 +01:00
Cancel the context when Main hands back no Control (#1889)
The goroutines Main starts stop only when its context does, and only a caller holding the Control can arrange that. Cancelling solely on error left a config test, which returns no Control and no error, with the lighthouse query worker and a hostname resolver per dns named static host running for the life of the process. Every embedder that validates a config in process rather than by exec'ing pays for that on each config load, dnclient and the apple clients included. Co-authored-by: Nate Brown <nbrown.us@gmail.com>
This commit is contained in:
1 parent
3a45c01656
commit
9651ffdb0d
2 files changed
+79
-2
No files matched your search
@@ -32,9 +32,12 @@ const _ = noiseutil.RejectHeadroom - 4*maxRoutines
|
||||
|
||||
func Main(c *config.C, configTest bool, buildVersion string, l *slog.Logger, deviceFactory overlay.DeviceFactory) (retcon *Control, reterr error) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
// Automatically cancel the context if Main returns an error, to signal all created goroutines to quit.
|
||||
// The goroutines started below stop only when this context does, and only a caller holding the
|
||||
// Control can arrange that. Cancel whenever we are not handing one back, which covers an error
|
||||
// and a config test alike: a config test used to leave the lighthouse query worker, and a
|
||||
// hostname resolver per dns named static host, running for the life of the process.
|
||||
defer func() {
|
||||
if reterr != nil {
|
||||
if retcon == nil {
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in new issue
Block a user