Skip to content

fix: settle async streams on executor rejection - #974

Open
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/async-stream-executor-rejection
Open

fix: settle async streams on executor rejection#974
sylvesterkaczmarek wants to merge 1 commit into
openai:mainfrom
sylvesterkaczmarek:fix/async-stream-executor-rejection

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Prevent AsyncStreamResponse from hanging when a subscriber-provided executor rejects the delivery task.

CompletableFuture.whenCompleteAsync(..., executor) reports executor dispatch failures through its dependent future. The current subscription path discards that future, so a rejected task can leave onCompleteFuture() pending indefinitely and the underlying response unclosed.

Fixes #973.

Changes

  • wrap the subscriber executor so dispatch failures settle onCompleteFuture() exceptionally;
  • close the asynchronous stream when that failure wins terminal settlement;
  • rethrow the executor failure so the dependent CompletableFuture retains normal exceptional-completion semantics;
  • keep handler delivery on the requested executor only, with no fallback execution on another thread;
  • add a deterministic regression using a rejecting executor.

Testing

  • pre-fix regression reproduced on current main: onCompleteFuture().get(100ms) timed out
  • ./gradlew :openai-java-core:test --tests com.openai.core.http.AsyncStreamResponseTest --no-daemon --console=plain — passed
  • ./gradlew :openai-java-core:lintKotlin --no-daemon --console=plain — passed
  • git diff --check — passed
  • Castiron custom-code budget check — passed, 1906 / 2000 lines with 94 lines headroom

Risk and rollout

Low. Successful executor dispatch and existing stream completion behavior are unchanged. The new path runs only when the supplied executor throws while accepting the delivery task. Older and normal executors retain the existing behavior.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner September 4, 2026 11:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T11:25:21.555627Z 7c77d21 PR opened
🔒 Security Review Completed 2026-09-04T11:25:26.037170Z 7c77d21 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncStreamResponse can hang when the subscriber executor rejects work

1 participant