Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thevilledev
Copy link
Collaborator

1. Why is this pull request needed and what does it do?

CoreDNS could deadlock when SIGTERM arrived during an in-flight reload. Caddy’s shutdown path held the instance mutex while the reload plugin’s final-shutdown callback attempted to send on an unbuffered channel. The reload goroutine was simultaneously trying to Restart (which needed the same mutex).

Changes to core:

  • Makes dnsserver.Server.Stop idempotent using sync.Once.

Changes to plugin/reload:

  • Reload channel is now buffered, so that final-shutdown send cannot block while the mutex is held.
  • Reloads during shutdown are gated by checking a quit signal.

Adds an integration test to validate this works properly.

2. Which issues (if any) are related?

Fixes #7314. Validated locally that the hang no longer happens. Depending on when the kill hits it, you might see this instead:

[INFO] Reloading
[INFO] SIGTERM: Shutting down servers then terminating
[ERROR] plugin/errors: 2 google.com. A: read udp 192.168.1.20:60548->192.168.9.10:53: i/o timeout
[INFO] plugin/reload: Running configuration SHA512 = 9468cd793a52124b50323392e8f1b543b545c49c139c2948afcdc6799216fcb8900372bd5f5fba0c138c75b8d455cd7d9cde342d9046b30f97d81b83a59d3264
[INFO] Reloading complete

And then shut down.

3. Which documentation changes (if any) need to be made?

None.

4. Does this introduce a backward incompatible change or deprecation?

No.

CoreDNS could deadlock when SIGTERM arrived during an in-flight
reload. Caddy’s shutdown path held the instance mutex while the
reload plugin’s final-shutdown callback attempted to send on an
unbuffered channel. The reload goroutine was simultaneously
trying to Restart (which needed the same mutex).

Changes:

- Makes dnsserver.Server.Stop idempotent using sync.Once.
- Reloads during shutdown are gated by checking a quit signal.

Adds an integration test to validate this works properly.

Signed-off-by: Ville Vesilehto <[email protected]>
@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 74.19355% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.17%. Comparing base (93c57b6) to head (35189d5).
⚠️ Report is 1655 commits behind head on master.

Files with missing lines Patch % Lines
core/dnsserver/server.go 80.95% 3 Missing and 1 partial ⚠️
plugin/reload/reload.go 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7562      +/-   ##
==========================================
+ Coverage   55.70%   62.17%   +6.47%     
==========================================
  Files         224      274      +50     
  Lines       10016    18306    +8290     
==========================================
+ Hits         5579    11382    +5803     
- Misses       3978     6251    +2273     
- Partials      459      673     +214     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yongtang yongtang merged commit 6ec3278 into coredns:master Sep 19, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin/reload deadlocks with SIGTERM

2 participants