Skip to content

THRIFT-5830: THttpTransport can now be used in interleaved async calls - #3978

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

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

Conversation

@birschick-bq

@birschick-bq birschick-bq commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

THRIFT-5830: Using THttpTransport using interleaved asynchronous calls may throw exception
Client: netstd

feat: Implement per-call transport support in THttpTransport

  • Added ITPerCallTransportProvider interface to define per-call transport creation.
  • Enhanced TBaseClient to support per-call transport with separate protocols.
  • Introduced THttpPerCallTransport for handling HTTP requests on a per-call basis.
  • Updated THttpTransport to manage lifecycle and creation of per-call transports.
  • Improved error handling and resource management in transport classes.
  • Updated tutorial with per-call semantics. Note: requires new version of Thrift.exe

Co-authored-by: Claude Sonnet 5
Co-authored-by: GPT 5.6 Luna
Co-authored-by: GitHub Copilot

  • 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.

@mergeable mergeable Bot added c# Pull requests that update C# code Pull requests that update .NET code compiler labels Sep 29, 2026
@birschick-bq
birschick-bq marked this pull request as ready for review September 29, 2026 03:19
Copilot AI balanced review requested due to automatic review settings September 29, 2026 03:19

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

Legacy .NET response reads can still block beyond configured deadlines, and the shared path may use a stale timeout.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Adds isolated per-call HTTP transports so generated .NET clients can safely perform interleaved asynchronous RPCs.

Changes:

  • Adds per-call transport creation and lifecycle management.
  • Updates client generation and protocol scoping for concurrent calls.
  • Adds concurrency, timeout, cancellation, and disposal tests.
File Description
lib/​netstd/​Thrift/​Transport/​ITPerCallTransportProvider.cs Defines per-call transport creation.
lib/​netstd/​Thrift/​Transport/​Client/​THttpTransport.cs Manages shared HTTP resources and per-call transports.
lib/​netstd/​Thrift/​Transport/​Client/​THttpPerCallTransport.cs Implements isolated request/response state.
lib/​netstd/​Thrift/​TBaseClient.cs Scopes protocols to each asynchronous call.
lib/​netstd/​Tests/​Thrift.Tests/​Transports/​THttpTransportTests.cs Tests concurrency and lifecycle behavior.
compiler/​cpp/​src/​thrift/​generate/​t_netstd_generator.cc Generates constructors and per-call execution wrappers.

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

Copilot AI review requested due to automatic review settings September 29, 2026 03:59

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

Response-body timeouts remain ineffective on .NET Framework for both HTTP read paths.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 29, 2026 04:24
@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v2/thrift-5830 branch from 9f68c22 to e5563ba Compare September 29, 2026 04: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.

Copilot review overview

🟡 Changes recommended

The commit message must use the repository-required THRIFT-5830: subject and Client: netstd line.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
Resolved since last review (1)

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

The new legacy .NET cancellation branch lacks runtime test coverage.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
Resolved since last review (1)

@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v2/thrift-5830 branch from 7216eb3 to 690ba28 Compare September 29, 2026 16:44
Copilot AI review requested due to automatic review settings September 29, 2026 16:44

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

The public provider path does not validate null transports and can mask failures with a secondary exception.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)

Comment thread lib/netstd/Thrift/TBaseClient.cs Resolved
Copilot AI review requested due to automatic review settings September 29, 2026 16:52

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

The close/write race and commit-format issue should be resolved before approval.

Review effort: Balanced
Findings: 1 Low severity

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

In code that hasn't changed since last review

Medium severity Normalize stream-close race to the transport NotOpen error

lib/​netstd/​Thrift/​Transport/​Client/​THttpTransport.cs:293

Close() can dispose this captured stream after the lifecycle lock is released but before WriteAsync starts, causing a raw ObjectDisposedException instead of the transport's NotOpen error. Normalize that close race as the other I/O paths do.

Comment thread lib/netstd/Thrift/TBaseClient.cs Resolved

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

Cross-target cancellation and concurrent resource-lifecycle behavior warrant final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v2/thrift-5830 branch from aed8a5b to c43e723 Compare October 2, 2026 19:57
@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v2/thrift-5830 branch 3 times, most recently from 4129483 to 6cf177d Compare October 2, 2026 21:50
…s may throw exception

Client: netstd

feat: Implement per-call transport support in THttpTransport

- Added ITPerCallTransportProvider interface to define per-call transport creation.
- Enhanced TBaseClient to support per-call transport with separate protocols.
- Introduced THttpPerCallTransport for handling HTTP requests on a per-call basis.
- Updated THttpTransport to manage lifecycle and creation of per-call transports.
- Improved error handling and resource management in transport classes.
- Updated tutorial with per-call semantics. Note: requires new version of Thrift.exe

Co-authored-by: Claude Sonnet 5
Co-authored-by: GPT 5.6 Luna
Co-authored-by: GitHub Copilot
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@birschick-bq
birschick-bq force-pushed the dev/birschick-bq/v2/thrift-5830 branch from 6cf177d to dc3f8f7 Compare October 2, 2026 22:03
@birschick-bq

Copy link
Copy Markdown
Contributor Author

@Jens-G
I've addressed the comments in the comment on the abandoned PR
#3930 (comment)

@birschick-bq

Copy link
Copy Markdown
Contributor Author

abandoning this change.

@Jens-G

Jens-G commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

I didnt have the time to look into it yet. You're giving up on this or you simply don't want to wait? @birschick-bq

@birschick-bq

Copy link
Copy Markdown
Contributor Author

I didnt have the time to look into it yet. You're giving up on this or you simply don't want to wait? @birschick-bq

@Jens-G
Sorry if it wasn't clear. I've replace this PR with a fully spec-driven AI solution here:
#4000

Any one of these three are working versions. The latest is probably the one to go with. But I'm open.

@birschick-bq
birschick-bq deleted the dev/birschick-bq/v2/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

c# Pull requests that update C# code Pull requests that update .NET code compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants