Skip to content

Make port descriptors caller-owned - #13518

Draft
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:fix-port-descriptor-api
Draft

Make port descriptors caller-owned#13518
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:fix-port-descriptor-api

Conversation

@bneradt

@bneradt bneradt commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Marking as a draft pending community approval from a dev@trafficserver.apache.org email.


TSPortDescriptorParse allocates an HttpProxyPort that plugins cannot
release, so every parsed descriptor leaks for the lifetime of Traffic
Server. The API also lacks end-to-end coverage for accepting
connections on a parsed port.

This patch replaces the pointer handle with caller-owned opaque storage
whose size and alignment are checked against HttpProxyPort. It updates
API users and adds an AuTest plugin that listens on a dynamically
selected port.

Fixes: #6894

Copilot AI lite review requested due to automatic review settings August 7, 2026 19:45
@bneradt bneradt added this to the 11.0.0 milestone Aug 7, 2026
@bneradt bneradt self-assigned this Aug 7, 2026
@bneradt bneradt removed the AuTest label Aug 7, 2026

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

This PR addresses a long-standing leak in the TSPortDescriptor API by changing the API from returning an unfreeable heap-allocated handle to using caller-owned opaque storage, and adds end-to-end coverage to verify a plugin can actually listen on a parsed descriptor.

Changes:

  • Redesign TSPortDescriptor to be caller-owned opaque storage; update TSPortDescriptorParse / TSPortDescriptorAccept signatures and all in-tree call sites.
  • Add an AuTest plugin + gold test that parses a dynamically selected port descriptor and successfully accepts a connection.
  • Remove the TSPortDescriptor regression-test leak suppression now that the leak is fixed.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
include/ts/apidefs.h.in Redefines TSPortDescriptor as caller-owned opaque storage.
include/ts/ts.h Updates API declarations and docs for the new parse/accept signatures and ownership model.
src/api/InkAPI.cc Implements storage-backed parsing (placement-new) and updates accept to use the new descriptor representation.
src/api/InkAPITest.cc Updates the regression test to use the new parse/accept API shape.
example/plugins/c-api/passthru/passthru.cc Updates example plugin to use the new parse/accept signatures.
tests/tools/plugins/port_descriptor.cc Adds an autest plugin that parses/accepts a descriptor and closes accepted connections.
tests/tools/plugins/CMakeLists.txt Builds the new port_descriptor autest plugin.
tests/gold_tests/pluginTest/port_descriptor/port_descriptor.test.py Adds a gold test that connects to the dynamically chosen descriptor port (via nc).
ci/asan_leak_suppression/regression.txt Drops the suppression for the previously-leaking regression test.

Comment thread src/api/InkAPI.cc
Comment thread src/api/InkAPI.cc Outdated
Comment thread src/api/InkAPI.cc
Comment thread src/api/InkAPITest.cc Outdated
Copilot AI review requested due to automatic review settings August 7, 2026 20:02
@bneradt
bneradt force-pushed the fix-port-descriptor-api branch from 31787d2 to c59e412 Compare August 7, 2026 20:02

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/api/InkAPI.cc:27

  • InkAPI.cc now uses std::is_trivially_destructible_v but does not include <type_traits> directly, relying on transitive includes. Add the header here to keep dependencies explicit and avoid build breaks if include graphs change.
#include <tuple>

include/ts/apidefs.h.in:1155

  • TSPortDescriptor’s opaque storage is hard-coded to 216 bytes with 8-byte alignment, while the implementation enforces exact size/alignment equality with HttpProxyPort. This is brittle across platform/compiler/flag variations and requires manual updates whenever HttpProxyPort layout changes. Consider generating the size/alignment into apidefs.h from the build (or providing headroom and using >= static_asserts) to reduce churn and portability risk.
class alignas(std::uint64_t) TSPortDescriptor
{
  friend TSReturnCode TSPortDescriptorParse(const char *, TSPortDescriptor *);
  friend TSReturnCode TSPortDescriptorAccept(const TSPortDescriptor *, struct tsapi_cont *);

private:
  std::byte _opaque[216];
};

Copilot AI review requested due to automatic review settings August 7, 2026 20:24
@bneradt
bneradt force-pushed the fix-port-descriptor-api branch from c59e412 to 229c40c Compare August 7, 2026 20:24

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

include/ts/apidefs.h.in:1156

  • TSPortDescriptorParse() placement-news HttpProxyPort into result->_opaque. Right now _opaque itself has alignment 1 (std::byte), so correct alignment relies on _opaque staying the first member and the class-level alignas not changing. If a future change adds a member before _opaque, the placement-new could become misaligned and trigger UB. Align _opaque itself so its address is always sufficiently aligned regardless of member ordering.
private:
  std::byte _opaque[216];
  bool      _is_valid{false};
};

TSPortDescriptorParse allocates an HttpProxyPort that plugins cannot
release, so every parsed descriptor leaks for the lifetime of Traffic
Server. The API also lacks end-to-end coverage for accepting
connections on a parsed port.

This patch replaces the pointer handle with caller-owned opaque storage
whose size and alignment are checked against HttpProxyPort. It updates
API users and adds an AuTest plugin that listens on a dynamically
selected port.

Fixes: apache#6894
@bneradt
bneradt force-pushed the fix-port-descriptor-api branch from 229c40c to c93d398 Compare August 7, 2026 20:32
Copilot AI review requested due to automatic review settings August 7, 2026 20:32

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

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@bneradt
bneradt marked this pull request as draft August 7, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with TSPortDescriptor (TS API).

2 participants