Skip to content

Commit d1dbe4e

Browse files
authored
fix panic if derp update is 0 (#2368)
* fix panic if derp update is 0 Fixes #2362 Signed-off-by: Kristoffer Dalby <[email protected]> * update changelog Signed-off-by: Kristoffer Dalby <[email protected]> --------- Signed-off-by: Kristoffer Dalby <[email protected]>
1 parent 9e3f945 commit d1dbe4e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
[#2364](https://github.com/juanfont/headscale/pull/2364)
1818
- Remove invalid routes and add stronger constraints for routes to avoid API panic
1919
[#2371](https://github.com/juanfont/headscale/pull/2371)
20+
- Fix panic when `derp.update_frequency` is 0
21+
[#2368](https://github.com/juanfont/headscale/pull/2368)
2022

2123
## 0.24.0 (2025-01-17)
2224

hscontrol/app.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ func (h *Headscale) scheduledTasks(ctx context.Context) {
245245

246246
lastExpiryCheck := time.Unix(0, 0)
247247

248-
derpTicker := time.NewTicker(h.cfg.DERP.UpdateFrequency)
249-
defer derpTicker.Stop()
250-
// If we dont want auto update, just stop the ticker
251-
if !h.cfg.DERP.AutoUpdate {
252-
derpTicker.Stop()
248+
derpTickerChan := make(<-chan time.Time)
249+
if h.cfg.DERP.AutoUpdate && h.cfg.DERP.UpdateFrequency != 0 {
250+
derpTicker := time.NewTicker(h.cfg.DERP.UpdateFrequency)
251+
defer derpTicker.Stop()
252+
derpTickerChan = derpTicker.C
253253
}
254254

255255
var extraRecordsUpdate <-chan []tailcfg.DNSRecord
@@ -285,7 +285,7 @@ func (h *Headscale) scheduledTasks(ctx context.Context) {
285285
h.nodeNotifier.NotifyAll(ctx, update)
286286
}
287287

288-
case <-derpTicker.C:
288+
case <-derpTickerChan:
289289
log.Info().Msg("Fetching DERPMap updates")
290290
h.DERPMap = derp.GetDERPMap(h.cfg.DERP)
291291
if h.cfg.DERP.ServerEnabled && h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {

0 commit comments

Comments
 (0)