Add the memory envelope, pprof, and a per-packet fix on the UDP path
A cgroup OOM kill is the worst outcome available to a resolver: an outage rather than a cache miss, with no chance to serve stale on the way out. So: - memory.limit / memory.reserve / memory.cache_max_bytes, a new config section. limit becomes a GOMEMLIMIT through debug.SetMemoryLimit, reduced by the reserve. The reserve exists because the Go heap does not account for goroutine stacks, runtime metadata, or the bbolt mmap backing the cache snapshot and the query log — handing the runtime the full cgroup limit is how you get killed by a mechanism that believed it had headroom. - config.Size, so a budget reads as "512MiB" rather than a byte count converted by hand. Strict about junk: "512MiBx" is an error. - The cache byte budget is now actually fed to the LRU. It already enforced maxBytes per shard on insert, but had no setter and nothing ever called one, so the footprint of cache.size was unbounded: one cached ANY or TXT answer can be tens of kilobytes, so 500k entries is anywhere from 150MB to several GB depending on what the traffic asked for. - api.pprof mounts net/http/pprof on the admin listener. The pprof handlers sit on the app-level mux, not inside the API's own handler, so they would bypass the auth middleware entirely; the option is therefore refused unless every admin address is loopback. Profiling means port-forwarding, so this is safe by construction rather than by policy, and cmdline cannot leak an argument that happens to be a key. - serveUDP was calling net.ResolveUDPAddr per packet. The peer already is a *net.UDPAddr; that call builds a string, re-parses the port and allocates on the busiest path in the process. Also fixes a flaky test: TestParallelPolicyAnswersFromTheFastestUpstream asserted the slow upstreams were hit, but the fan-out cancels on the first answer, so whether they were dispatched before cancellation is a real race. It now asserts the answer came from the fast upstream and that nothing waited.
This commit is contained in:
1 parent
1bdb0b081c
commit
b0e6b3bb92
11 files changed
+382
-6
No files matched your search
@@ -146,6 +146,39 @@ fixed in `internal/zonefile` + `internal/localzone`:
|
||||
Expansion skips YAML comments, so documenting `${VAR}` in the ConfigMap does
|
||||
not break the file.
|
||||
|
||||
### Memory envelope (added)
|
||||
|
||||
`memory.limit` / `memory.reserve` / `memory.cache_max_bytes` are new. `limit`
|
||||
becomes a `GOMEMLIMIT` via `debug.SetMemoryLimit`, reduced by `reserve`; the
|
||||
cache byte budget is wired into the LRU, which already enforced `maxBytes` per
|
||||
shard but had no setter and was never fed one.
|
||||
|
||||
Rationale: a cgroup OOM kill is the worst outcome available to a resolver — an
|
||||
outage rather than a cache miss, with no chance to serve stale on the way out.
|
||||
`GOMEMLIMIT` turns the same limit into a soft one the GC works towards. The
|
||||
reserve exists because the Go heap does not account for goroutine stacks,
|
||||
runtime metadata, or the bbolt mmap backing the cache snapshot and the query log
|
||||
— handing the runtime the full cgroup limit is how you get killed by a mechanism
|
||||
that believed it had headroom.
|
||||
|
||||
`ParseSize` accepts `512MiB`, `2GiB`, `1000` (bytes), and is strict about junk
|
||||
(`512MiBx` is an error). `config.Size` has no test coverage yet — **that is the
|
||||
first thing to add**.
|
||||
|
||||
### Known red
|
||||
|
||||
- `internal/config`: `TestLoadUnsetEnvIsFatalAndNamesVariable` fails. The
|
||||
fixture now has a blocklist entry, so `Validate` passes, but the expected
|
||||
`${FD_TEST_MISSING}` expansion error never fires — `Load` returns the
|
||||
*Validate* error instead. `TestExpandEnvErrors` covers the same
|
||||
reference-in-a-flow-sequence case and passes, so the difference is specific to
|
||||
the quoted, flow-sequence form `api_keys: ["${X}"]`. Undiagnosed; do not
|
||||
assume the expander is fine.
|
||||
- `internal/qlog` and `internal/localzone` have test files mid-write from
|
||||
subagents that ran out of budget. `internal/qlog` does not compile
|
||||
(`internal/... /qlog.go:520: undefined: liveEntry`, `viewsFor: undefined:
|
||||
Resize`). Fix that before anything else in those packages.
|
||||
|
||||
### Open decision
|
||||
|
||||
- **Unknown config keys are silently ignored.** Writing `block:` where the
|
||||
|
||||
Reference in new issue
Block a user