Skip to content

Fix data race in xfr.go#8039

Merged
thevilledev merged 1 commit into
coredns:masterfrom
rpb-ant:file-xfr-tree-race
Apr 11, 2026
Merged

Fix data race in xfr.go#8039
thevilledev merged 1 commit into
coredns:masterfrom
rpb-ant:file-xfr-tree-race

Conversation

@rpb-ant

@rpb-ant rpb-ant commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

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

Fixes a data race in xfr.go

2. Which issues (if any) are related?

#8038

go test -race -run '^TestSecondaryZoneNotify$' -count=200 -cpu=2,4 ./test/

pretty reliably triggers a race for me on master, and with this fix it reliably passes

$ go test -race -run '^TestSecondaryZoneNotify$' -count=200 -cpu=2,4 ./test/
ok      github.com/coredns/coredns/test 80.972s

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

none

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

none

Comment thread plugin/file/xfr.go
Comment on lines +24 to +27
z.RLock()
apex, err := z.apexIfDefinedLocked()
t := z.Tree
z.RUnlock()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am evaluating whether z.ApexIfDefined() should expand to include z.Tree so that we don't have to do this awkward manual lock.

That would (naively) be a backwards-incompatible change, happy to take advice from maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately I could keep z.ApexIfDefined() unchanged and have it internally delegate to a new private method that returns apex, tree, err

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the current approach is fine. It's consistent with how Lookup already snapshots under a single read lock:

z.RLock()
ap := z.Apex
tr := z.Tree
z.RUnlock()

Difference is that Transfer needs the assembled []dns.RR slice. I think the locking intention is clear here, and it's only for a single call site.

@thevilledev thevilledev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Looks like it's been there for quite a while.

Can you fix the DCO? Other than that I think it's ready to go

Comment thread plugin/file/xfr.go
Comment on lines +24 to +27
z.RLock()
apex, err := z.apexIfDefinedLocked()
t := z.Tree
z.RUnlock()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the current approach is fine. It's consistent with how Lookup already snapshots under a single read lock:

z.RLock()
ap := z.Apex
tr := z.Tree
z.RUnlock()

Difference is that Transfer needs the assembled []dns.RR slice. I think the locking intention is clear here, and it's only for a single call site.

Signed-off-by: Ryan Brewster <rpb@anthropic.com>
@rpb-ant rpb-ant force-pushed the file-xfr-tree-race branch from 16ffee2 to f717dae Compare April 11, 2026 04:13
@rpb-ant

rpb-ant commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

Great, hopefully fixed DCO

@thevilledev thevilledev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM

@thevilledev thevilledev merged commit 0ed3aae into coredns:master Apr 11, 2026
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.

2 participants