Skip to content

fix(dns): use write lock when updating cache entry addresses - #1932

Open
magic-peach wants to merge 1 commit into
kmesh-net:mainfrom
magic-peach:fix-dns-resolve-rlock-write
Open

fix(dns): use write lock when updating cache entry addresses#1932
magic-peach wants to merge 1 commit into
kmesh-net:mainfrom
magic-peach:fix-dns-resolve-rlock-write

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

/kind bug

resolve() grabs RLock before doing entry.Addresses = addrs, which is a read lock and gives no protection against a concurrent writer. If two refreshes for the same domain land at the same time (easy to hit once refreshDns is running against a live queue), they race writing to the same slice field.

Switched both to Lock/Unlock, matching how the rest of the mutating paths in this file already handle the cache (RemoveUnwatchDomain, AddDomainInQueue, etc).

Added a test that spins up several concurrent resolve() calls for one domain. Confirmed it flags the race under -race on main and is clean with the fix.

Fixes: N/A, found by reading through the resolver while poking at something else.

NONE

resolve() takes RLock before writing entry.Addresses, which is a read
lock and doesn't actually protect against concurrent writers. Two
refreshes for the same domain landing at once race on that write -
easy to hit under -race with a couple of goroutines resolving the same
domain.

Switched it to Lock/Unlock like the rest of the mutating paths in this
file already do. Added a test that fires several concurrent resolve()
calls for one domain and runs clean under -race with the fix, and
reliably flags the race without it.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
Copilot AI lite review requested due to automatic review settings August 17, 2026 17:31
@kmesh-bot kmesh-bot added the kind/bug Something isn't working label Aug 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kmesh-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.50%. Comparing base (32fe3df) to head (982bdcb).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Coverage Δ
pkg/dns/dns.go 53.45% <100.00%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae15e8a...982bdcb. Read the comment docs.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants