Skip to content

Fix data race between rule-set updates and matching - #4353

Open
solodecode wants to merge 1 commit into
SagerNet:testingfrom
solodecode:agent/fix-ruleset-reload-race
Open

Fix data race between rule-set updates and matching#4353
solodecode wants to merge 1 commit into
SagerNet:testingfrom
solodecode:agent/fix-ruleset-reload-race

Conversation

@solodecode

Copy link
Copy Markdown

LocalRuleSet.reloadRules and RemoteRuleSet.updateOnce replace s.rules under access, while Match, String, ExtractIPSet, and mergeableRule read it without taking the lock. A local reload or remote update can therefore race with active route matching.

Read s.rules through a snapshot taken under RLock, and protect the writes in Cleanup and Close with Lock. Add a regression test that updates local and remote rule-sets while concurrent readers call Match, String, and mergeableRule.

Tested with go test -race ./route/rule.

@solodecode
solodecode marked this pull request as ready for review July 27, 2026 02:12
@nekohasekai
nekohasekai force-pushed the testing branch 3 times, most recently from b7bf9cf to a90fcbc Compare July 27, 2026 09:41
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from 00334d3 to 555ac63 Compare July 27, 2026 13:43
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from 555ac63 to 30c122e Compare July 28, 2026 00:48
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from 30c122e to cb056cc Compare July 28, 2026 13:21
@nekohasekai
nekohasekai force-pushed the testing branch 7 times, most recently from f49758b to 1569c52 Compare July 29, 2026 11:17
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from cb056cc to ad918d6 Compare July 29, 2026 13:15
@nekohasekai
nekohasekai force-pushed the testing branch 2 times, most recently from 067b00f to 4f7f894 Compare July 29, 2026 13:44
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from ad918d6 to 548aff2 Compare July 29, 2026 23:48
@nekohasekai
nekohasekai force-pushed the testing branch 2 times, most recently from 2557cf6 to f141553 Compare July 31, 2026 08:16
@solodecode
solodecode force-pushed the agent/fix-ruleset-reload-race branch from 548aff2 to 9671e8a Compare July 31, 2026 11:51
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.

1 participant