Skip to content

ProxyProtocol: free pp_info heap on NetVConnection recycle#13293

Merged
moonchen merged 1 commit into
apache:masterfrom
moonchen:mchen/proxyprotocol-free-pp-info
Jun 18, 2026
Merged

ProxyProtocol: free pp_info heap on NetVConnection recycle#13293
moonchen merged 1 commit into
apache:masterfrom
moonchen:mchen/proxyprotocol-free-pp-info

Conversation

@moonchen

Copy link
Copy Markdown
Contributor

Problem

NetVConnection embeds ProxyProtocol pp_info by value, and ProxyProtocol owns heap (the additional_data string and the parsed tlv map). has_proxy_protocol() parses an inbound PROXY v2 header into pp_info once per connection, allocating both.

The NetVC ClassAllocators are Destruct_on_free=false, so ~ProxyProtocol never runs when a VC is recycled and UnixNetVConnection::clear() did not release pp_info. The slot's next placement-new then abandons the string buffer and map nodes — leaking once per recycled connection that carried a PROXY v2 header, i.e. every inbound connection behind a PROXY-protocol load balancer.

Fix

Add ProxyProtocol::reset() and call it from UnixNetVConnection::clear(), the single recycle chokepoint (SSL and QUIC clear() chain to it, and clear() runs only on the free path). reset() swaps the members with empty containers rather than clear()ing them, since clear() keeps capacity that the recycle would still abandon. Releasing pp_info in clear() is safe: it is read only while the VC is live.

Targeted rather than flipping the allocators to Destruct_on_free=true, which would run the full destructor chain on top of the existing manual clear()/free_thread() teardown and needs a separate idempotency audit.

NetVConnection embeds a ProxyProtocol by value, and a PROXY v2 header parsed
by has_proxy_protocol() heap-allocates ProxyProtocol::additional_data (the TLV
blob) plus the tlv map. The NetVConnection ClassAllocators are
Destruct_on_free=false, so ~ProxyProtocol never runs when a VC is recycled and
UnixNetVConnection::clear() did not release pp_info -- the next placement-new on
the recycled slot abandoned the buffer and map nodes, leaking once per recycled
connection that carried a PROXY v2 header. Behind a PROXY-protocol load
balancer that is every inbound connection.

Add ProxyProtocol::reset() and call it from UnixNetVConnection::clear() (the
single recycle chokepoint for the Unix, SSL and QUIC VCs). reset() swaps the
members with empty containers rather than clear()ing them, because clear()
retains capacity that the recycle would still abandon.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a per-connection heap leak when UnixNetVConnection instances are recycled after parsing PROXY v2 headers. Because netVCAllocator is configured with Destruct_on_free=false, embedded members’ destructors (including ProxyProtocol) don’t run on recycle, so heap owned by pp_info must be explicitly released during clear().

Changes:

  • Add ProxyProtocol::reset() to release heap-owned state and restore default values.
  • Call pp_info.reset() from UnixNetVConnection::clear() to ensure recycled VCs don’t leak PROXY-protocol state.
  • Add a unit test covering ProxyProtocol::reset() and its idempotency.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/iocore/net/UnixNetVConnection.cc Resets pp_info during clear() so PROXY v2 heap allocations don’t persist across VC recycle.
include/iocore/net/ProxyProtocol.h Introduces ProxyProtocol::reset() to drop TLVs/additional data and restore default fields.
src/iocore/net/unit_tests/test_ProxyProtocol.cc Adds a unit test ensuring reset() clears parsed PROXY v2 state and is safe to call repeatedly.

Comment thread include/iocore/net/ProxyProtocol.h
@moonchen moonchen self-assigned this Jun 17, 2026
@moonchen moonchen added this to the 11.0.0 milestone Jun 17, 2026

@JosiahWI JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@moonchen moonchen merged commit 95a13a5 into apache:master Jun 18, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: For v10.2.0

Development

Successfully merging this pull request may close these issues.

3 participants