#3499·headscale

[Bug] Serve goroutines are forcefully stopped

Author: gabriel-vasileCreated Sep 26, 2026Updated Sep 26, 2026
Labelsbug

Is this a support request?

  • This is not a support request

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Serve has several context.Background()s passed to goroutines, ex: https://github.com/juanfont/headscale/blob/393dd3e2d94e7d999b423d0265b21014a98b6ca0/hscontrol/app.go#L632 In turn, the goroutines sometimes kill the whole program with log.Fatal: https://github.com/juanfont/headscale/blob/393dd3e2d94e7d999b423d0265b21014a98b6ca0/hscontrol/derp/server/derp_server.go#L352-L356 That makes it so the other goroutines will get killed while they are doing their work (serve network requests, run scheduled tasks, etc.)

Expected Behavior

Goroutines started by Serve use the same base context. When that context is cancelled, goroutines observe it and stop their in-progress work.

Steps To Reproduce

I don't have steps, but this kind of problem causes:

  • errors on client-side: their network responses are cut midway
  • program does not respond to shutdown signals
  • if one goroutine errors the program keeps working with unhealthy state
  • timing/flaky issues at shutdown

Environment

markdown
- OS: -
- Headscale version: main
- Tailscale version: -

Runtime environment

  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

Debug information

n/a