Skip to content

Fix AutoPagerAsync hang when first-page handler throws#763

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/autopager-async-onnext-throw
Open

Fix AutoPagerAsync hang when first-page handler throws#763
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/autopager-async-onnext-throw

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • catch synchronous exceptions thrown while handling the first page in AutoPagerAsync.subscribe
  • still call handler.onComplete(...), complete onCompleteFuture() exceptionally, and close the pager
  • add regression coverage for onNext() throwing on the first page and a later page

Why

If handler.onNext() throws while iterating the first page, firstPage.handle() throws before it can return a CompletableFuture. That skips the existing whenComplete path, so onComplete never runs and onCompleteFuture() can remain unresolved.

Validation

  • env JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home PATH=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home/bin:$PATH ./gradlew :openai-java-core:test --tests com.openai.core.AutoPagerAsyncTest
  • env JAVA_HOME=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home PATH=/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home/bin:$PATH ./gradlew :openai-java-core:lintKotlin

@fallintoplace fallintoplace requested a review from a team as a code owner June 27, 2026 20:22
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.

1 participant