DNS: recvLoop spins at 100%+ CPU on a successful zero-byte read (regression in 1.14 for "type": "local")
On the integrity requirements, stated up front rather than ticked: the configuration below is minimal, local, and involves no remote server, no TUN and no graphical client. But the trigger on this machine is a closed-source enterprise EDR NetworkExtension content filter, so I cannot honestly claim the repro is free of closed-source software, and I have not ticked that box. What does not depend on it is the code-path analysis:
readResponsereturns(nil, nil)on a successful-but-unparseable read andrecvLooptreats that as an unboundedcontinuewith no invalidation. That is verifiable by inspection in v1.14.2 and v1.15.0-alpha.9, and is the whole of the report. Close it if that is not enough to act on.
Operating system
macOS
System version
macOS 26.6.2 (build 25G83, Darwin 25.6.0), Apple Silicon / arm64
Installation type
Original command line program (official release binary)
Version
sing-box version 1.14.2Compared against sing-box version 1.13.14 on the same machine with the same
config. Code paths below also checked against v1.15.0-alpha.9.
Description
When a macOS NetworkExtension content filter (a third-party enterprise EDR
agent, installed as a networkFilter system extension) tears down an idle DNS
socket, sing-box busy-loops at ~120% of a core indefinitely and silently, while
name resolution keeps working. There is nothing in the log at warn, and the
process never recovers.
This is a regression in 1.14 for "type": "local". v1.13.14 is unaffected
on the same machine with the same config; v1.14.2 spins. The same trigger also
affects "type": "udp" on both versions, so the underlying loop is older —
but 1.14 newly routes the local (system resolver) transport through it, which
is what makes it reachable in an otherwise ordinary macOS configuration.
Process CPU time, sampled every 20 s. One request through the inbound, then completely idle:
"type": "local" — the regression
| elapsed | v1.13.14 | v1.14.2 |
|---|---|---|
| 0 s | 0:00.02 | 0:00.05 |
| 20 s | 0:00.03 | 0:14.96 |
| 40 s | 0:00.04 | 0:43.95 |
| 60 s | 0:00.05 | 1:12.97 |
v1.13.14 is flat. v1.14.2 reaches 2:07 of CPU and does not recover.
"type": "udp" — both affected
| elapsed | v1.13.14 | v1.14.2 |
|---|---|---|
| 0 s | 0:00.02 | 0:00.06 |
| 40 s | 0:40.87 | 0:44.08 |
| 80 s | 1:33.46 | 1:41.97 |
Why 1.14 regressed for local
dns/transport/local/local_shared.go changed from a per-query exchange to a
persistent pooled transport.
v1.13.14 — one exchange per query, no long-lived socket, no receive loop:
response, err := t.exchangeOne(ctx, M.ParseSocksaddr(server), question,
config.timeout, config.useTCP, config.trustAD)v1.14.2 — builds and starts a UDPTransport per system resolver, which carries
the shared multiplexer and its receive loop:
serverTransport = transport.NewUDPRaw(t.logger,
dns.NewTransportAdapter(C.DNSTypeUDP, "", nil), t.dialer, serverAddr)
err := serverTransport.Start(adapter.StartStateStart)Root cause
A read that succeeds but yields nothing parseable is not treated as an error, and the read count is discarded.
dns/transport/udp.go:
_, err := buffer.ReadOnceFrom(conn) // n dropped; a 0-byte read is not an error
if err != nil {
return nil, err
}
var message mDNS.Msg
err = message.Unpack(buffer.Bytes())
if err != nil {
t.logger.Debug("discarded malformed UDP response: ", err)
return nil, nil // -> "no message, no error"
}dns/transport/multiplexer.go:
for {
message, err := m.options.readNext(conn)
if err != nil { ...Invalidate...; return }
conn.readEpoch.Add(1)
if message == nil {
continue // unbounded; conn is never invalidated
}
m.complete(message.Id, message, nil, true)
}Once the filter puts the socket into a state where reads return zero bytes with no error, this never terminates and never backs off.
Suggested fix
Either alone would end the loop:
Treat a zero-length read as a read error, so the connection is invalidated:
n, err := buffer.ReadOnceFrom(conn) if err != nil { return nil, err } if n == 0 { return nil, io.ErrUnexpectedEOF }Bound the
message == nilpath inrecvLoop: count consecutive unparseable reads and invalidate past a small threshold. That would also stop a peer flooding malformed datagrams from pinning a core.
recvLoop and readResponse are identical in v1.14.2 and v1.15.0-alpha.9.
Reproduction
Config (local only — no remote server involved):
{
"log": { "level": "warn" },
"dns": { "servers": [ { "type": "local", "tag": "sys" } ] },
"inbounds": [ { "type": "mixed", "tag": "in", "listen": "127.0.0.1", "listen_port": 17899 } ],
"outbounds": [ { "type": "direct", "tag": "direct" } ],
"route": {
"default_domain_resolver": "sys",
"rules": [ { "inbound": "in", "action": "resolve", "server": "sys" } ]
},
"experimental": { "debug": { "listen": "127.0.0.1:19091" } }
}- Run it, issue exactly one request —
curl -x http://127.0.0.1:17899 https://www.baidu.com/— then leave the process completely idle. - Sample cumulative CPU with
ps -o time= -p <pid>every 20 s (not%CPU, which is a decaying average and misleads here). - Swap
"type": "local"for{"type":"udp","server":"223.5.5.5","server_port":53}for the second table.
Caveat on reproducibility, stated plainly: the trigger on this machine is a
NetworkExtension content filter that closes the idle DNS socket ~10 s after a
reply, after which reads return 0 bytes with no error. Without such a filter this
config will not spin, so a maintainer cannot reproduce it by running the config
alone. What is machine-independent is the code path: readResponse returning
(nil, nil) on an unparseable read, and recvLoop treating that as continue
with no bound and no invalidation. Any condition that yields a successful
zero-byte or unparseable read reaches it.
Logs
goroutine?debug=2 taken while spinning, "type": "local" on v1.14.2 — note it
lands in the UDP transport:
github.com/sagernet/sing-box/dns/transport.(*UDPTransport).readResponse
dns/transport/udp.go:160
github.com/sagernet/sing-box/dns/transport.(*queryMultiplexer).recvLoop
dns/transport/multiplexer.go:429With "type": "udp" on v1.14.2 the goroutine is in state [running] — the read
returns without ever parking in IO wait:
goroutine 334 [running]:
internal/poll.(*FD).Read
net.(*netFD).Read
github.com/sagernet/sing/common/buf.(*Buffer).ReadOnceFrom
github.com/sagernet/sing-box/dns/transport.(*UDPTransport).readResponse
dns/transport/udp.go:155
github.com/sagernet/sing-box/dns/transport.(*queryMultiplexer).recvLoop
dns/transport/multiplexer.go:429v1.13.14 with "type": "udp" spins in its own pre-multiplexer loop
(dns/transport/udp.go:230), which is why that row is affected too.
Nothing is emitted at log.level: warn throughout — the spin is silent.
Source: SagerNet/sing-box