Skip to content

fix(gax): do not treat a SocketTimeoutException as a thread interrupt - #14778

Merged
lqiu96 merged 1 commit into
googleapis:mainfrom
lqiu96:fix/gax-socket-timeout-not-interrupt
Oct 26, 2026
Merged

lqiu96 merged 1 commit into
googleapis:mainfrom
lqiu96:fix/gax-socket-timeout-not-interrupt

Conversation

@lqiu96

@lqiu96 lqiu96 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #12860

This PR originally created by @markaddleman (thanks for the contribution!). Re-created on this PR to resolve the merge conflicts.

Summary

Supersedes #14578 (recreated with merge conflicts resolved in DirectRetryingExecutorTest).

DirectRetryingExecutor.submit catches InterruptedIOException and sets the current thread's interrupt flag. SocketTimeoutException extends InterruptedIOException, so an HTTP connect or read timeout also sets the flag, although no thread was interrupted. setAttemptFuture then calls Future.get, which sees the flag and throws a new InterruptedException. The SocketTimeoutException is lost, and the retry algorithm judges an InterruptedException in its place. A caller sees an InterruptedException from an unknown sender.

This change catches SocketTimeoutException first and passes it to the retry algorithm unchanged. A real interrupt (InterruptedException, any other InterruptedIOException, ClosedByInterruptException) keeps the current path.

DirectRetryingExecutor.submit catches InterruptedIOException and sets the current thread's interrupt flag. SocketTimeoutException extends InterruptedIOException, so an HTTP connect or read timeout also sets the flag, although no thread was interrupted. setAttemptFuture then calls Future.get, which sees the flag and throws a new InterruptedException. The SocketTimeoutException is lost, and the retry algorithm judges an InterruptedException in its place. A caller sees an InterruptedException from an unknown sender.

Catch SocketTimeoutException first and give it to the retry algorithm unchanged. A real interrupt (InterruptedException, other InterruptedIOException, ClosedByInterruptException) keeps the old path.

Supersedes googleapis#14578

Related to googleapis#12860

Co-authored-by: Mark Addleman <markaddleman@gmail.com>
@lqiu96
lqiu96 requested a review from a team as a code owner October 26, 2026 18:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies DirectRetryingExecutor to explicitly catch SocketTimeoutException separately from other InterruptedIOException instances. Because a socket timeout represents a network timeout rather than a thread interruption, handling it separately prevents the thread's interrupt flag from being set, allowing the retry algorithm to properly evaluate and retry the timeout. Corresponding unit tests have been added to verify this behavior. There are no review comments to evaluate, and I have no additional feedback to provide as the implementation is correct and well-tested.

@lqiu96
lqiu96 merged commit 7b91805 into googleapis:main Oct 26, 2026
286 of 297 checks passed
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.

[sdk-platform-java] DirectRetryingExecutor re-interrupts the thread before recording interrupt-related attempt failure

2 participants