diff --git a/CHANGELOG.md b/CHANGELOG.md index a06a2ad1..c159d01d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ [#2364](https://github.com/juanfont/headscale/pull/2364) - Remove invalid routes and add stronger constraints for routes to avoid API panic [#2371](https://github.com/juanfont/headscale/pull/2371) +- Fix panic when `derp.update_frequency` is 0 + [#2368](https://github.com/juanfont/headscale/pull/2368) ## 0.24.0 (2025-01-17) diff --git a/hscontrol/app.go b/hscontrol/app.go index 3349392b..641f5d42 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -245,11 +245,11 @@ func (h *Headscale) scheduledTasks(ctx context.Context) { lastExpiryCheck := time.Unix(0, 0) - derpTicker := time.NewTicker(h.cfg.DERP.UpdateFrequency) - defer derpTicker.Stop() - // If we dont want auto update, just stop the ticker - if !h.cfg.DERP.AutoUpdate { - derpTicker.Stop() + derpTickerChan := make(<-chan time.Time) + if h.cfg.DERP.AutoUpdate && h.cfg.DERP.UpdateFrequency != 0 { + derpTicker := time.NewTicker(h.cfg.DERP.UpdateFrequency) + defer derpTicker.Stop() + derpTickerChan = derpTicker.C } var extraRecordsUpdate <-chan []tailcfg.DNSRecord @@ -285,7 +285,7 @@ func (h *Headscale) scheduledTasks(ctx context.Context) { h.nodeNotifier.NotifyAll(ctx, update) } - case <-derpTicker.C: + case <-derpTickerChan: log.Info().Msg("Fetching DERPMap updates") h.DERPMap = derp.GetDERPMap(h.cfg.DERP) if h.cfg.DERP.ServerEnabled && h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {