You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
THRIFT-5830: THttpTransport can now be used in interleaved async calls - #3978
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.
…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>
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c#Pull requests that update C# code Pull requests that update .NET codecompiler
4 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
THRIFT-5830: Using THttpTransport using interleaved asynchronous calls may throw exception
Client: netstd
feat: Implement per-call transport support in THttpTransport
Co-authored-by: Claude Sonnet 5
Co-authored-by: GPT 5.6 Luna
Co-authored-by: GitHub Copilot
[skip ci]anywhere in the commit message to free up build resources.