Skip to content

GH-55396 : [C++][FlightRPC] Add async gRPC server - #55419

Draft
Alex-PLACET wants to merge 2 commits into
apache:mainfrom
Alex-PLACET:feature/async-grpc-generic-server
Draft

Alex-PLACET wants to merge 2 commits into
apache:mainfrom
Alex-PLACET:feature/async-grpc-generic-server

Conversation

@Alex-PLACET

@Alex-PLACET Alex-PLACET commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for opening a pull request!

If this is your first pull request you can find detailed information on how to contribute here:

Please remove this line and the above text before creating your pull request.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

This PR includes breaking changes to public APIs. (If there are any breaking changes to public APIs, please explain which changes are breaking. If not, you can remove this.)

This PR contains a "Critical Fix". (If the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld), please provide explanation. If not, you can remove this.)

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Serve Flight RPCs on gRPC's generic callback API so handlers return
arrow::Future and never occupy a worker thread while waiting.

Motivation: the synchronous transport runs every RPC on a gRPC worker
thread that the handler occupies until it returns, so throughput is bounded
by the thread pool (which grows at most ~1 thread/second) rather than by the
work in flight.  Clients already have an async path; servers had none.

API (server_async.h, flight_data_decoder.h):
- AsyncGenericFlightServerBase: *Async handlers returning arrow::Future;
  unoverridden handlers answer NotImplemented.
- AsyncFlightDataStream / AsyncFlightListing / AsyncResultStream: pull-based
  iterators, one item requested and written at a time.
- AsyncFlightMessageReader / AsyncFlightMessageWriter: DoExchange halves.
- AsyncFlightDataListener / AsyncFlightDataWriter: push-based DoPut, with
  PutResult metadata sendable from any thread.

Transport (transport/grpc/async_grpc_*.cc):
- One translation unit per part of the transport: service dispatch, DoGet,
  DoPut, DoExchange (reader, writer and reactor), Handshake, the streaming
  trio and the unary trio.
- AsyncGenericFlightService creates one reactor per RPC from the method name;
  unknown methods get a fallback reactor answering UNIMPLEMENTED, so the
  typed sync service is not registered alongside it.
- DoGet is served on a write-only bidi reactor: the generic callback API has
  no server-streaming reactor.
- Reactors refcount themselves, since gRPC's callback API has no holds; write
  buffers are reactor members because StartWrite requires them to outlive
  the call.
- DoPut serializes its PutResult writes: WriteMetadata() runs on the
  listener's thread while OnReadDone()/OnWriteDone() run on gRPC callback
  threads, and a half-close arriving mid-write now waits for the slot instead
  of starting a second write on the same buffer.
- AsyncCallContext carries the call context; middleware and auth go through
  the shared GrpcServerCallContextHelper.

Fixes found while building this:
- Signal teardown ordering: Serve() published the server as the signal
  target before its self-pipe and shutdown callback were initialized, and
  did not restore handlers when it failed partway.
- SIGPIPE: waking the signal thread with SelfPipe::Shutdown() closed the
  read end, so a handler entering just before that killed the process;
  wake with a plain payload instead.
- Shutdown() on an uninitialized server cleared the process-wide signal
  target, disabling signal shutdown for another serving instance.  Serve(),
  Shutdown() and Wait() now validate before entering the signal helper.
- Sync/async lifecycle duplication: Init/Serve/Shutdown/Wait/port/location
  moved into internal::ServerLifecycle, owned by both server classes.
- Location::uri() returns Result<util::Uri>, which needs util::Uri complete
  (Result embeds AlignedStorage<T>): include arrow/util/uri.h from types.h
  instead of forward-declaring it.
- ToGrpcStatus had no CallbackServerContext overload, needed to attach the
  Arrow status trailers from a reactor.
- Middleware CallCompleted was skipped for unknown methods.
- DoPut had no PutResult write-back channel while an upload was in flight.
- A PutResult write started while the ending ack was in flight overwrote the
  write buffer; the ending ack is now deferred until the slot is free.
- OnFinish() is application code and may call back into the listener's
  writer; the transport no longer holds its write lock across it.
- gRPC 1.65 is required for the async server only; the async client paths
  still need 1.40, and ARROW_GRPC_REQUIRED_VERSION returns to 1.30.0.

Tests: the async transport tests are split by the transport part each one
covers, with the shared fixtures in async_grpc_test_fixtures.h.  The
synchronous server's suites are unchanged.

Known limitations: a blocking ServerAuthHandler is refused (it would run on
callback threads) in favour of Handshake/ValidateToken; a handler that
abandons its future blocks Shutdown() until a deadline; request arguments
are call-scoped.
@github-actions github-actions Bot added the awaiting review Awaiting review label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #55396 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Awaiting review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant