Copilot commented on code in PR #13769:
URL: https://github.com/apache/trafficserver/pull/13769#discussion_r4156621076
##########
src/proxy/http/HttpTransact.cc:
##########
@@ -5112,6 +5112,49 @@
HttpTransact::handle_no_cache_operation_on_forward_server_response(State *s)
return;
}
+// Revalidation merges in older builds deleted and re-added caching headers on
every 304, and a cache
+// round trip left each dead slot unreclaimable, so a long-lived object's
cached response could grow
+// to hundreds of field blocks. Deleted slots are now reused, but a header's
blocks are never
+// released and every copy and marshal keeps them, so such a header stays
bloated for as long as it
+// is cached and each revalidation rewrites all of it. When it holds well over
the blocks its live
+// fields need, replace it with a copy of just its live fields, in slot order
so field and duplicate
+// order are unchanged. The copy has to land in a fresh heap: copying onto the
existing one frees the
+// dead blocks but leaves their space inside the region that marshal writes to
disk.
+bool
+HttpTransact::compact_cached_response_header(HTTPHdr *cached_header)
+{
+ int blocks = 0;
+
+ for (MIMEFieldBlockImpl const *fblock =
&cached_header->m_mime->m_first_fblock; fblock != nullptr; fblock =
fblock->m_next) {
+ ++blocks;
+ }
+ int const live = cached_header->fields_count();
+
+ if (blocks <= live / MIME_FIELD_BLOCK_SLOTS + 2) {
+ return false;
+ }
+
+ int const before = cached_header->m_heap->marshal_length();
+ HTTPHdr compact;
+
+ compact.create(HTTPType::RESPONSE, cached_header->version_get());
Review Comment:
`HTTPHdr::create` does not assign this version to `m_version`;
`http_hdr_init` hardcodes `HTTP_1_0` and uses the argument only to add HTTP/2/3
pseudo-fields (`src/proxy/hdrs/HTTP.cc:226-255`). Consequently, compaction
downgrades an HTTP/1.1 cached response to HTTP/1.0, and for HTTP/2/3 can inject
a synthetic `:status` before copying the existing fields. Create the empty
response without protocol pseudo-fields and then set its version explicitly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]