Files
blocky/server
Dimitri Herzog db8d889b7b fix(server): compress responses larger than 512 bytes (#2213)
* fix(server): compress responses larger than 512 bytes

Since #2102 the server lets Truncate decide compression, and Truncate
clears Compress whenever the message already fits uncompressed. Fitting
the buffer the client advertised is not sufficient: that client may be a
forwarder relaying our answer to a stub resolver with a smaller buffer,
and it can only truncate what it received.

A query arriving via such a forwarder carries the forwarder's OPT record,
so getMaxResponseSize returns its buffer (1232 or more) rather than 512.
An eight-record A answer for a 45-byte name is 562 bytes uncompressed and
202 compressed: both fit 1232, so we now send the uncompressed one, and
the forwarder has to truncate it for its non-EDNS0 clients -- typically by
dropping every section, leaving them with TC and no answer at all. Before
#2102 the same answer went out compressed, fit 512, and was relayed intact.

Compress anything that would not fit a bare 512-byte UDP message so it
survives that hop. Below that threshold there is nothing to gain, so the
compression-map alloc #2102 set out to avoid is still skipped for the
short responses that make up the bulk of the traffic.

Fixes #2212

* test(server): guard that the compression regression test stays meaningful

Assert the answer really exceeds 512 bytes uncompressed, so shrinking the
RR set can't leave the test passing without exercising the scenario.
2026-08-11 05:18:07 +02:00
..