Skip to content

Async transports: executeAsync routes only adaptation failures through the future, not later synchronous throws #120

@OmarAlJarrah

Description

@OmarAlJarrah

Follow-up from #119.

#119 made executeAsync route a requestAdapter.adapt(...) failure through the returned CompletableFuture instead of throwing on the caller's thread. The guard wraps the adapt(...) call only; the dispatch kickoff that runs immediately after — still on the caller's thread, before the future is handed back — is not covered.

  • OkHttp is already safe here: client.newCall(...) does no throwing work, and a RejectedExecutionException from a shut-down dispatcher is delivered through Callback.onFailure → the future. No change needed.
  • JDK calls client.sendAsync(...) outside the guard. sendAsync does not guarantee that every failure arrives through the returned future — e.g. invoking it on a closed java.net.http.HttpClient (JDK 21+, where the client is AutoCloseable) throws synchronously. Such a throw would escape on the caller's thread — the same inconsistency executeAsync throws request-adaptation failures synchronously instead of via the returned future #118 set out to remove.

This needs a closed/misconfigured client rather than a normal request, so it is low-probability and filed separately from #118 rather than folded into #119.

Proposed change

Extend the JDK executeAsync try/catch to also enclose client.sendAsync(...) (and the bridgeAsyncResponse(...) wiring), so any synchronous throw from dispatch is returned as a failed future, matching the async error-delivery contract. Leave OkHttp as-is, optionally with a short comment noting why its post-adapt path is already future-safe.

Acceptance

  • A synchronous throw from the JDK dispatch path surfaces through the returned future, not on the caller's thread.
  • The executeAsync KDoc's error-delivery contract holds for the whole method body, not just adaptation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sdk-coresdk-core toolkittech-debtsimplification / cleanup

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions