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

Skip to content

Conversation

@bn-smayr
Copy link
Contributor

@bn-smayr bn-smayr commented Jul 1, 2025

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

This PR fixes a data race that occurs when a cached DNS message is served by multiple goroutines. In this case the TTL of resource records is accessed and modified concurrently and go's race detector reports the following:

WARNING: DATA RACE
Write at 0x00c000a7e344 by goroutine 1264:
  github.com/coredns/coredns/plugin/cache.filterRRSlice()
      coredns/plugin/cache/dnssec.go:15 +0x118
  github.com/coredns/coredns/plugin/cache.(*item).toMsg()
      coredns/plugin/cache/item.go:90 +0x668
  github.com/coredns/coredns/plugin/cache.(*Cache).ServeDNS()
      coredns/plugin/cache/handler.go:79 +0x1064
  github.com/coredns/coredns/core/dnsserver.(*Server).ServeDNS()
      coredns/core/dnsserver/server.go:364 +0xcf5
...

Previous read at 0x00c000a7e340 by goroutine 1265:
  github.com/miekg/dns.(*CNAME).copy()
      pkg/mod/github.com/miekg/[email protected]/ztypes.go:898 +0x46
  github.com/miekg/dns.Copy()
      pkg/mod/github.com/miekg/[email protected]/msg.go:1065 +0x1b8
  github.com/coredns/coredns/plugin/cache.filterRRSlice()
      coredns/plugin/cache/dnssec.go:17 +0x79
  github.com/coredns/coredns/plugin/cache.(*item).toMsg()
      coredns/plugin/cache/item.go:90 +0x668
  github.com/coredns/coredns/plugin/cache.(*Cache).ServeDNS()
      coredns/plugin/cache/handler.go:79 +0x1064
  github.com/coredns/coredns/core/dnsserver.(*Server).ServeDNS()
      coredns/core/dnsserver/server.go:364 +0xcf5
  ...

2. Which issues (if any) are related?

Fixes #6718, pretty much as suggested by @DmitriyMV.

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

None

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

No

@bn-smayr bn-smayr changed the title fix(cache): race condition when updating the TTL of cached messages fix(cache): data race when updating the TTL of cached messages Jul 1, 2025
@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.98%. Comparing base (93c57b6) to head (8cc431b).
Report is 1516 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7397      +/-   ##
==========================================
+ Coverage   55.70%   59.98%   +4.28%     
==========================================
  Files         224      273      +49     
  Lines       10016    17982    +7966     
==========================================
+ Hits         5579    10787    +5208     
- Misses       3978     6566    +2588     
- Partials      459      629     +170     

☔ 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 06da7dc into coredns:master Jul 3, 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.

data-race: filterRRSlice function mutates original which it got from the shared cache

2 participants