Add configurable DNS query timeout#4079
Open
comebackto2021 wants to merge 59 commits intoSagerNet:testingfrom
Open
Add configurable DNS query timeout#4079comebackto2021 wants to merge 59 commits intoSagerNet:testingfrom
comebackto2021 wants to merge 59 commits intoSagerNet:testingfrom
Conversation
`SecTrustEvaluateWithError` is serial
This reverts commit 62cb06c.
DNS rules referencing rule-sets that contain only ip_cidr predicates silently stopped matching when legacy DNS mode was disabled, because the IP-CIDR branch cannot match against an in-flight DNS query. The existing validation intentionally let every rule_set through on the premise that mixed sets still work via their non-IP branches, which is only true when such a branch exists. Track whether a rule-set carries any non-IP-CIDR predicate and reject pure-IP references the same way bare ip_cidr fields are already rejected.
Serialize probe rounds in startProber to eliminate unbounded fan-out of fire-and-forget probe goroutines (up to 100/sec per direction), and close HTTP/3 transports via transport.Close() in addition to CloseIdleConnections.
1b0e6c5 to
abedea4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
timeoutfield toDNSconfiguration so the DNS exchange timeout canbe tuned per-deployment via JSON config. Previously hardcoded to
C.DNSTimeout = 10sindns/client.go.The
Client.timeoutfield is already parameterized in code —NewClient()accepts
options.Timeoutand falls back toC.DNSTimeoutwhen zero. ThisPR only wires up the JSON option and threads it through
dns.NewRouter.Motivation
On unstable mobile networks (carrier-grade NAT with aggressive timeouts,
DPI middleboxes on TCP/53), plain TCP DNS sockets can become "zombies"
after long idle periods — bytes are silently dropped while the kernel
still considers the socket valid. The full 10-second timeout is then
user-visible latency on the first query after inactivity.
Industry comparison for DNS exchange/per-attempt timeouts:
RES_TIMEOUTOperators deploying sing-box across many users on heterogeneous networks
have no way to tune this without forking and shipping custom libbox builds
to every client platform (Android AAR, Apple framework, Windows DLL).
Changes
option/dns.go: addTimeout badoption.DurationtoDNSClientOptionsdns/router.go: pass it todns.NewClientvia existingClientOptions.Timeoutdocs/configuration/dns/index.mdandindex.zh.md: document the new fieldBackward compatibility
Field is
omitempty. When unset (time.Duration(0)),dns/client.go:80-82falls back to
C.DNSTimeout = 10s, preserving existing behavior. Nomigration needed.
Example
{ "dns": { "timeout": "3s", "servers": [...] } }Verification
go build ./...— passesgo vet ./option/... ./dns/...— cleango test ./option/... ./dns/...— all green"timeout": "3s"accepted, invalid duration string rejectedwith clear error pointing to
dns.timeoutJSON path