Skip to content

THRIFT-5830: Add per-call transport support for netstd - #4000

Closed
birschick-bq wants to merge 1 commit into
apache:masterfrom
birschick-bq:dev/birschick-bq/v3/thrift-5830
Closed

birschick-bq wants to merge 1 commit into
apache:masterfrom
birschick-bq:dev/birschick-bq/v3/thrift-5830

Conversation

@birschick-bq

@birschick-bq birschick-bq commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

THRIFT-5830: Add per-call transport support for netstd
Client: cpp,netstd

Add opt-in per-call transports for generated asynchronous clients, isolating HTTP and layered transport state while preserving existing shared-protocol constructors.

Preserve caller-configured HTTP timeouts and propagate the linked cancellation token through generated request and response operations. Add focused transport, lifecycle, concurrency, timeout, generator, and tutorial coverage.

Co-Authored-By: GitHub Copilot

Note: AI/OpenSpec artifacts are completely optional. Let me know if you want to keep these or have me remove them.

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

@birschick-bq
birschick-bq requested a review from Jens-G as a code owner October 6, 2026 20:23
Copilot AI balanced review requested due to automatic review settings October 6, 2026 20:24
@mergeable mergeable Bot added c# Pull requests that update C# code Pull requests that update .NET code compiler github_actions Pull requests that update GitHub Actions code labels Oct 6, 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.

Copilot review overview

🟡 Changes recommended

Wrapper capability detection, HTTP option preservation, and undiscoverable GitHub configuration introduce functional gaps.

Review effort: Balanced
Findings: 4 High severity · 3 Medium severity · 3 Low severity

Open (10)
What changed in this PR

Adds opt-in per-call transport isolation for concurrent asynchronous netstd RPC clients.

Changes:

  • Adds per-call transport APIs, generated constructors, cancellation, timeout, and lifecycle handling.
  • Adds concurrency and transport tests plus tutorial coverage.
  • Adds documentation and OpenSpec/Copilot configuration.
File Description
tutorial/​netstd/​smoketest.sh Exercises per-call tutorial mode.
tutorial/​netstd/​README.md Documents tutorial usage.
tutorial/​netstd/​Client/​Program.cs Implements concurrent per-call example.
lib/​netstd/​Thrift/​Transport/​Layered/​TFramedTransport.cs Delegates per-call framed transports.
lib/​netstd/​Thrift/​Transport/​Layered/​TBufferedTransport.cs Delegates per-call buffered transports.
lib/​netstd/​Thrift/​Transport/​ITPerCallTransportProvider.cs Defines the provider contract.
lib/​netstd/​Thrift/​Transport/​Client/​THttpTransport.cs Adds isolated HTTP state and leasing.
lib/​netstd/​Thrift/​TBaseClient.cs Manages call-scoped protocols and deadlines.
lib/​netstd/​Tests/​Thrift.Tests/​Transports/​THttpTransportTests.cs Tests supplied HTTP timeouts.
lib/​netstd/​Tests/​Thrift.Tests/​Transports/​THttpTransportPerCallTests.cs Tests HTTP concurrency and lifecycle.
lib/​netstd/​Tests/​Thrift.Tests/​Transports/​TBaseClientPerCallTests.cs Tests client and wrapper behavior.
lib/​netstd/​README.md Documents the public feature.
lib/​netstd/​per-call-transport.md Records feature requirements.
lib/​netstd/​openspec/​specs/​per-call-transport/​spec.md Defines capability scenarios.
lib/​netstd/​openspec/​specs/​.gitkeep Retains the specs directory.
lib/​netstd/​openspec/​config.yaml Configures OpenSpec.
lib/​netstd/​openspec/​changes/​archive/​2026-10-06-per-call-transport/​tasks.md Archives implementation tasks.
lib/​netstd/​openspec/​changes/​archive/​2026-10-06-per-call-transport/​specs/​per-call-transport/​spec.md Archives the specification delta.
lib/​netstd/​openspec/​changes/​archive/​2026-10-06-per-call-transport/​proposal.md Archives the proposal.
lib/​netstd/​openspec/​changes/​archive/​2026-10-06-per-call-transport/​design.md Archives design decisions.
lib/​netstd/​openspec/​changes/​archive/​2026-10-06-per-call-transport/​.openspec.yaml Records archive metadata.
lib/​netstd/​openspec/​changes/​archive/​.gitkeep Retains the archive directory.
lib/​netstd/​.github/​workflows/​copilot-setup-steps.yml Adds Copilot setup automation.
lib/​netstd/​.github/​agents/​openspec.agent.md Defines an OpenSpec agent.
compiler/​cpp/​src/​thrift/​generate/​t_netstd_generator.cc Generates per-call client APIs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/agents/openspec.agent.md Resolved
Comment thread lib/netstd/per-call-transport.md Resolved
Comment thread lib/netstd/per-call-transport.md Resolved
Comment thread tutorial/netstd/README.md Resolved
Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:04
@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v3/thrift-5830 branch from 1efff86 to a510284 Compare October 6, 2026 21:04
@mergeable mergeable Bot added the build and general CI cmake, automake and build system changes label Oct 6, 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.

Comment thread lib/netstd/Makefile.am Resolved
Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:25

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.

Copilot review overview

🟡 Changes recommended

Buffered-wrapper construction can leak its call-owned transport, and unrelated recurring OpenSpec CI infrastructure should be separated.

Review effort: Balanced
Findings: 4 Medium severity · 1 Low severity

Open (5)
Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Remove unrelated third-party CLI workflow from this PR

.github/​workflows/​copilot-setup-steps.yml:36

This introduces a permanent third-party CLI installation workflow that is unrelated to the per-call transport change described by the PR. Because the workflow is triggered for every lib/netstd/** push and pull request but only prints the CLI version (it runs neither transport tests nor openspec validate), it adds recurring CI/network cost without validating this feature; move the OpenSpec agent/setup infrastructure to a separate PR or remove it here.

Medium severity Dispose returned transport when wrapper construction fails

lib/​netstd/​Thrift/​Transport/​Layered/​TBufferedTransport.cs:105

If constructing the buffered wrapper throws after the provider has returned its call-owned transport (for example, while reading a custom transport's Configuration), that transport is leaked. This method owns the returned transport and should dispose it on wrapper-construction failure, as the framed implementation does.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:34

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.

Copilot review overview

🔵 Needs a closer look

Buffered transport construction can leak acquired resources, and packaging and CI scope issues remain unresolved.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Avoid running Copilot setup on every netstd push and pull request

.github/​workflows/​copilot-setup-steps.yml:17

These triggers run a global npm installation on every future netstd push and pull request, but the job only prints the CLI version and does not validate the checked-in specs or source. That adds an unrelated external dependency and CI job to all netstd changes; keep this Copilot setup workflow dispatch-only, or turn it into actual OpenSpec validation in a separately scoped tooling change.

Client: cpp,netstd

Add opt-in per-call transports for generated asynchronous clients, isolating
HTTP and layered transport state while preserving existing shared-protocol
constructors.

Preserve caller-configured HTTP timeouts and propagate the linked cancellation
token through generated request and response operations. Add focused transport,
lifecycle, concurrency, timeout, generator, and tutorial coverage.

Co-Authored-By: GitHub Copilot
Copilot AI balanced review requested due to automatic review settings October 6, 2026 21:47
@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v3/thrift-5830 branch from 44823b1 to 01c379e Compare October 6, 2026 21:47

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.

Copilot review overview

🔵 Needs a closer look

The cross-cutting generator, concurrency, timeout, and resource-lifetime changes warrant final human validation across supported targets.

Review effort: Balanced
Findings: None

Resolved since last review (4)

@birschick-bq

Copy link
Copy Markdown
Contributor Author

@Jens-G
Note: AI/OpenSpec artifacts are completely optional. Let me know if you want to keep these or have me remove them.

Comment on lines +19 to +20
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Install OpenSpec CLI
run: npm install -g @fission-ai/openspec@1.14.1
@birschick-bq

Copy link
Copy Markdown
Contributor Author

closing. Will submit another PR in its place.

@Jens-G

Jens-G commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

openspec artifacts

I definitely see the value (use it myself), I also know that e.g. Apache Causeway does it, yet not sure about the sentiment at Thrift. Could be a good dev@ question.

@birschick-bq

@birschick-bq
birschick-bq deleted the dev/birschick-bq/v3/thrift-5830 branch October 29, 2026 17:46
birschick-bq added a commit to birschick-bq/thrift that referenced this pull request Nov 1, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The System names that the option adds to the output are fully
  qualified (global::System.Exception in the timeout catch clause), so an
  IDL type named Exception cannot capture them.
- Output without the option is byte-identical to before. Using "isolated"
  needs a thrift compiler built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout). Catch tests for the option. Compile fixtures
  (IsolatedCall.thrift, IsolatedExceptionName.thrift) for netstandard2.0,
  net8, net9 and net10.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly.
- lib/netstd/README.md documents usage, timeouts, ownership and
  multiplexing; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
birschick-bq added a commit to birschick-bq/thrift that referenced this pull request Nov 1, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The System names that the option adds to the output are fully
  qualified (global::System.Exception in the timeout catch clause), so an
  IDL type named Exception cannot capture them.
- Output without the option is byte-identical to before. Using "isolated"
  needs a thrift compiler built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport). Catch tests for
  the option. Compile fixtures
  (IsolatedCall.thrift, IsolatedExceptionName.thrift) for netstandard2.0,
  net8, net9 and net10.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly.
- lib/netstd/README.md documents usage, timeouts, ownership and
  multiplexing; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test were written by Jens Geyer,
with the AI assistance noted in his trailer below, and are included
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
birschick-bq added a commit to birschick-bq/thrift that referenced this pull request Nov 2, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents. Cancellation that arrives while a call view is being created
  disposes the view and fails the creation, even when the creator ignores
  the token. An HTTP call view that is disposed while its request is
  pending releases the late response and fails the flush with NotOpen. It
  reads at most what the message size limit still allows, so a buffered
  layer that prefetches a full buffer does not reject a small valid reply.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The names that the option adds to the output are fully qualified, the
  System ones (global::System.Exception in the timeout catch clause) and
  the Thrift types (global::Thrift.TCallContext and so on), and the
  inherited members IsCallIsolated and CreateCallContextAsync are reached
  through base. An IDL type or method with one of these names cannot
  capture them. The context variable gets a name that is free in each
  method, so the parameters of the shared-protocol and high-level
  operations keep the names of the IDL.
- Output without the option is byte-identical to before. Using "isolated"
  needs a thrift compiler built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport, cancellation
  during view creation, a late response, a small reply under a low size
  limit). Catch tests for the option. Compile fixtures (IsolatedCall.thrift,
  IsolatedExceptionName.thrift, IsolatedNames.thrift) for netstandard2.0,
  net8, net9 and net10.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly. CI runs it with
  -Isolated next to the existing run.
- lib/netstd/README.md documents usage, timeouts, ownership, multiplexing
  and that a service and its base service both need the option; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test were written by Jens Geyer,
with the AI assistance noted in his trailer below, and are included
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
birschick-bq added a commit to birschick-bq/thrift that referenced this pull request Nov 2, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents. Cancellation that arrives while a call view is being created
  disposes the view and fails the creation, even when the creator ignores
  the token. An HTTP call view that is disposed while its request is
  pending releases the late response and fails the flush with NotOpen. It
  reads at most what the message size limit still allows, so a buffered
  layer that prefetches a full buffer does not reject a small valid reply.
  The call views of HTTP and memory honor the token of every write overload
  and the memory view that of a read, so a cancelled or timed-out call does
  not keep reading or modifying its buffer. Creating a context
  synchronously checks the token before and after the view is created, as
  the asynchronous path does, and a context that cannot be built disposes
  the protocol as well as the view.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The names that the option adds to the output are fully qualified, the
  System ones (global::System.Exception in the timeout catch clause) and
  the Thrift types (global::Thrift.TCallContext and so on), and the
  inherited members IsCallIsolated and CreateCallContextAsync are reached
  through a cast to the client base class, not through base, which is the
  client of the parent for a service that extends another service. An IDL
  type or method with one of these names cannot capture them. The
  context variable gets a name that is free in each
  method, so the parameters of the shared-protocol and high-level
  operations keep the names of the IDL.
- Output without the option is byte-identical to before. Using "isolated"
  needs a thrift compiler built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport, cancellation
  during view creation, a late response, a small reply under a low size
  limit, cancelled writes and reads of call views, synchronous creation
  with a cancelled token, an ancestor service with methods named like
  client members). Catch tests for the option. Compile fixtures (IsolatedCall.thrift,
  IsolatedExceptionName.thrift, IsolatedNames.thrift) for netstandard2.0,
  net8, net9 and net10.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly. CI runs it with
  -Isolated next to the existing run.
- lib/netstd/README.md documents usage, timeouts, ownership, multiplexing
  and that a service and its base service both need the option; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test were written by Jens Geyer,
with the AI assistance noted in his trailer below, and are included
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Jens-G added a commit to birschick-bq/thrift that referenced this pull request Nov 11, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents. Cancellation that arrives while a call view is being created
  disposes the view and fails the creation, even when the creator ignores
  the token. An HTTP call view that is disposed while its request is
  pending releases the late response and fails the flush with NotOpen. It
  reads at most what the message size limit still allows, so a buffered
  layer that prefetches a full buffer does not reject a small valid reply.
  The call views of HTTP and memory honor the token of every write overload
  and the memory view that of a read, so a cancelled or timed-out call does
  not keep reading or modifying its buffer. Creating a context
  synchronously checks the token before and after the view is created, as
  the asynchronous path does, and a context that cannot be built disposes
  the protocol as well as the view.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The names that the option adds to the output are fully qualified, the
  System ones (global::System.Exception in the timeout catch clause) and
  the Thrift types (global::Thrift.TCallContext and so on), and the
  inherited members IsCallIsolated and CreateCallContextAsync are reached
  through a cast to the client base class, not through base, which is the
  client of the parent for a service that extends another service. An IDL
  type or method with one of these names cannot capture them. The
  context variable gets a name that is free in each
  method, so the parameters of the shared-protocol and high-level
  operations keep the names of the IDL.
- Output without the option is byte-identical to before. Using "isolated"
  needs a thrift compiler built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport, cancellation
  during view creation, a late response, a small reply under a low size
  limit, cancelled writes and reads of call views, synchronous creation
  with a cancelled token, an ancestor service with methods named like
  client members). Catch tests for the option. Compile fixtures (IsolatedCall.thrift,
  IsolatedExceptionName.thrift, IsolatedNames.thrift) for netstandard2.0,
  net8, net9 and net10.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly. CI runs it with
  -Isolated next to the existing run.
- lib/netstd/README.md documents usage, timeouts, ownership, multiplexing
  and that a service and its base service both need the option; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test were written by Jens Geyer,
with the AI assistance noted in his trailer below, and are included
unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Jens-G added a commit to birschick-bq/thrift that referenced this pull request Nov 12, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents. Cancellation that arrives while a call view is being created
  disposes the view and fails the creation, even when the creator ignores
  the token. An HTTP call view that is disposed while its request is
  pending releases the late response and fails the flush with NotOpen. It
  reads at most what the message size limit still allows, so a buffered
  layer that prefetches a full buffer does not reject a small valid reply.
  The call views of HTTP and memory honor the token of every write overload
  and the memory view that of a read, so a cancelled or timed-out call does
  not keep reading or modifying its buffer. Creating a context
  synchronously checks the token before and after the view is created, as
  the asynchronous path does, and a context that cannot be built disposes
  the protocol as well as the view.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The names that the option adds to the output are fully qualified, the
  System ones (global::System.Exception in the timeout catch clause) and
  the Thrift types (global::Thrift.TCallContext and so on), and the
  inherited members IsCallIsolated and CreateCallContextAsync are reached
  through a cast to the client base class, not through base, which is the
  client of the parent for a service that extends another service. An IDL
  type or method with one of these names cannot capture them. The
  context variable gets a name that is free in each
  method, so the parameters of the shared-protocol and high-level
  operations keep the names of the IDL.
- A client method that hides a member of TBaseClient is declared new:
  any method named IsCallIsolated, and one named CreateCallContext or
  CreateCallContextAsync without arguments, as the cancellation token is
  then its only parameter, the same as for the TBaseClient methods. The
  Thrift.Compile projects treat CS0108 and CS0109 as errors.
- Apart from that new modifier, output without the option is
  byte-identical to before. Using "isolated" needs a thrift compiler
  built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport, cancellation
  during view creation, a late response, a small reply under a low size
  limit, cancelled writes and reads of call views, synchronous creation
  with a cancelled token, an ancestor service with methods named like
  client members, methods named like the TBaseClient members). Catch
  tests for the option. Compile fixtures (IsolatedCall.thrift,
  IsolatedExceptionName.thrift, IsolatedNames.thrift) for netstandard2.0,
  net10 and net11.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly. CI runs it with
  -Isolated next to the existing run.
- lib/netstd/README.md documents usage, timeouts, ownership, multiplexing
  and that a service and its base service both need the option; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

Every await that the change adds to the library and to the generated
code uses ConfigureAwait(false), as lib/netstd requires since
THRIFT-6538.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR apache#3930, apache#3978 and apache#4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test, and the new modifier for
client methods that hide TBaseClient members, were written by Jens
Geyer, with the AI assistance noted in his trailer below, and are
included unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Jens-G added a commit that referenced this pull request Nov 12, 2026
Client: netstd,cpp

Asynchronous calls that overlap on one client share a protocol and its
transport, so their requests and responses can corrupt each other, for
example over THttpTransport. Add opt-in support that gives every call its
own transport view and protocol. Behavior and generated output without the
new option are unchanged.

Runtime (lib/netstd):
- ICallIsolatedTransport hands out one transport view per call; the caller
  owns and disposes it. IAsyncCallIsolatedTransport adds asynchronous
  creation, and IPerCallTimeoutTransport lets a transport declare a
  per-call timeout (unbounded by default).
- THttpTransport and TMemoryBufferTransport implement them. A view owns its
  request buffer and response, releases them on success, failure and
  cancellation, and reports NotOpen once disposed. Disposing or cancelling
  one view does not affect any other. Once the shared transport is
  disposed, THttpTransport, the isolated layers and, as of the change by
  Jens Geyer included here, TMemoryBufferTransport refuse to create call
  views and throw ObjectDisposedException, as ICallIsolatedTransport
  documents. Cancellation that arrives while a call view is being created
  disposes the view and fails the creation, even when the creator ignores
  the token. An HTTP call view that is disposed while its request is
  pending releases the late response and fails the flush with NotOpen. It
  reads at most what the message size limit still allows, so a buffered
  layer that prefetches a full buffer does not reject a small valid reply.
  The call views of HTTP and memory honor the token of every write overload
  and the memory view that of a read, so a cancelled or timed-out call does
  not keep reading or modifying its buffer. Creating a context
  synchronously checks the token before and after the view is created, as
  the asynchronous path does, and a context that cannot be built disposes
  the protocol as well as the view.
- TIsolatedBufferedTransport and TIsolatedFramedTransport only wrap
  call-isolated transports. Passing a legacy TBufferedTransport or
  TFramedTransport to the new constructor does not compile.
- TCallContext carries a call's protocol, its sequence id, its cancellation
  token and an optional timeout. A reply with a different sequence id is
  rejected with BadSequenceId. The transport's timeout and a timeout given
  for one call are linked with the caller's token, the shortest wins, and a
  timeout is reported as TTransportException TimedOut, distinct from
  cancellation by the caller. The timeout of the underlying HttpClient
  (ConnectTimeout) also bounds every request of an HTTP call view; when it
  elapses without a cancellation by the caller, the view reports TimedOut
  too. The legacy THttpTransport is unchanged.
- TBaseClient gains a constructor for a call-isolated transport and a
  protocol factory, CreateCallContext and CreateCallContextAsync, and
  IsCallIsolated. The existing constructors keep working; SeqId now
  increments atomically.

Generator (compiler/cpp):
- New netstd option "isolated". A client generated with it keeps the legacy
  constructors and gains the call-isolated constructor, each with XML
  documentation that says when to use it. High-level operations use a
  per-call context when the client was built with the new constructor and
  the shared protocols otherwise. send_ and recv_ keep their signatures and
  gain overloads that take a TCallContext, so replies can be received out
  of order.
- The names that the option adds to the output are fully qualified, the
  System ones (global::System.Exception in the timeout catch clause) and
  the Thrift types (global::Thrift.TCallContext and so on), and the
  inherited members IsCallIsolated and CreateCallContextAsync are reached
  through a cast to the client base class, not through base, which is the
  client of the parent for a service that extends another service. An IDL
  type or method with one of these names cannot capture them. The
  context variable gets a name that is free in each
  method, so the parameters of the shared-protocol and high-level
  operations keep the names of the IDL.
- A client method that hides a member of TBaseClient is declared new:
  any method named IsCallIsolated, and one named CreateCallContext or
  CreateCallContextAsync without arguments, as the cancellation token is
  then its only parameter, the same as for the TBaseClient methods. The
  Thrift.Compile projects treat CS0108 and CS0109 as errors.
- Apart from that new modifier, output without the option is
  byte-identical to before. Using "isolated" needs a thrift compiler
  built from this change.

Tests and documentation:
- Unit tests for transports, layers, call context, timeouts and generated
  clients (overlapping calls, out-of-order receive, one-way calls,
  exceptions, mismatched replies, cancellation, timeouts, multiplexed
  protocol, constructor shape, an IDL that defines an Exception type, the
  HttpClient timeout, a disposed shared memory transport, cancellation
  during view creation, a late response, a small reply under a low size
  limit, cancelled writes and reads of call views, synchronous creation
  with a cancelled token, an ancestor service with methods named like
  client members, methods named like the TBaseClient members). Catch
  tests for the option. Compile fixtures (IsolatedCall.thrift,
  IsolatedExceptionName.thrift, IsolatedNames.thrift) for netstandard2.0,
  net10 and net11.
- The codegen harness gains -Isolated, checks the constructor
  documentation, and now detects Windows correctly. CI runs it with
  -Isolated next to the existing run.
- lib/netstd/README.md documents usage, timeouts, ownership, multiplexing
  and that a service and its base service both need the option; tutorial/netstd gets an -isolated example and a smoke test
  case; Makefile.am lists TCallContext.cs.

Every await that the change adds to the library and to the generated
code uses ConfigureAwait(false), as lib/netstd requires since
THRIFT-6538.

No breaking changes for users who do not opt in. Supersedes the earlier
approaches in PR #3930, #3978 and #4000.

AI assistance: the runtime classes, generator changes, tests and
documentation were largely written with AI assistance and then reviewed
and tested by the author. The change to TMemoryBufferTransport (refuse
call views once it is disposed) and its test, and the new modifier for
client methods that hide TBaseClient members, were written by Jens
Geyer, with the AI assistance noted in his trailer below, and are
included unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Jens Geyer <jensg@apache.org>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build and general CI cmake, automake and build system changes c# Pull requests that update C# code Pull requests that update .NET code compiler github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants