mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-10-28 12:56:51 +08:00
Follow-up review of 525654e found:
1. Log gating was incomplete: only the direct/route path was gated;
cache-hit/cache-miss, proxy and dispatcher per-query logs were still
unconditional log.Printf (the hottest paths under load). Gate them
behind V2RAYA_DNS_DEBUG=1 too; error logs stay visible.
2. Stopping the transparent proxy left the direct nat OUTPUT/PREROUTING
REDIRECT --to-port 52353 rules and the fwmark 0x80 exemption rules in
place (Tproxy/Redirect GetCleanCommands only clean their own chains).
Once the DNS module exits, local DNS queries hit a dead port and DNS
fails. Add cleanDnsRedirectRules() and run it on the normal stop path.
3. module.go bootstrap client inlined its own markFd + marked dialer;
reuse newMarkedDnsClient (keeping the 3s fail-fast timeout).
4. dnsLogf/dnsDebugEnabled were duplicated in socket_unix.go /
socket_windows.go; move them to a common debug.go.
5. No unit tests for newMarkedDnsClient; add tests asserting
Net/UDPSize/Timeout and a non-nil Dialer.Control.
Verified: go build ./dns/... ./kernel/v2ray/... ; go test ./dns/...
29 lines
769 B
Go
29 lines
769 B
Go
package dns
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
// dnsDebugEnabled controls per-query verbose logging. It is disabled by
|
|
// default because at info level every DNS query logs 2-3 lines; under a
|
|
// high query load (e.g. cloud-agent monitoring traffic) that log storm
|
|
// consumes CPU/IO/memory and can OOM the process. Enable with
|
|
// V2RAYA_DNS_DEBUG=1 when troubleshooting.
|
|
var dnsDebugEnabled = func() bool {
|
|
v, err := strconv.ParseBool(os.Getenv("V2RAYA_DNS_DEBUG"))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return v
|
|
}()
|
|
|
|
// dnsLogf logs a line only when verbose DNS debug logging is enabled.
|
|
// High-frequency per-query logs MUST use this instead of log.Printf.
|
|
func dnsLogf(format string, args ...interface{}) {
|
|
if dnsDebugEnabled {
|
|
log.Printf(format, args...)
|
|
}
|
|
}
|