GH-6318: Recover from stale pooled connections in OpenAI OkHttp client#6323
Open
sdudzin wants to merge 1 commit into
Open
GH-6318: Recover from stale pooled connections in OpenAI OkHttp client#6323sdudzin wants to merge 1 commit into
sdudzin wants to merge 1 commit into
Conversation
…AI OkHttp client Fixes spring-projectsGH-6318 (spring-projects#6318) * re-enable OkHttp's retryOnConnectionFailure (the OkHttp default) in SpringAiOpenAiHttpClient. With it disabled, when a server like llama.cpp closes an idle keep-alive connection, the next request reuses that dead connection and fails with "unexpected end of stream" / EOFException instead of being silently retried on a fresh connection. * the previous code disabled this flag thinking it would duplicate the OpenAI SDK's RetryingHttpClient. The two work at different layers: OkHttp's flag retries broken connections instantly with no backoff; the SDK's retries are based on HTTP status codes (408/429/5xx) and use exponential backoff. They do not overlap, so there is no duplication. * add SpringAiOpenAiHttpClientTests: a configuration guard plus a MockWebServer test that reproduces the EOFException recovery using SocketPolicy.DISCONNECT_AT_END (a stale pooled connection). Signed-off-by: Siarhei Dudzin <606713+sdudzin@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6318.
When the OpenAI client talks to a server that closes idle keep-alive connections (e.g. llama.cpp), the next request reuses the dead connection and fails with
EOFException: \n not found: limit=0/unexpected end of stream.The cause:
SpringAiOpenAiHttpClientsetretryOnConnectionFailure(false)to "avoid doubling" with the SDK'sRetryingHttpClient. They are not the same thing — OkHttp's flag silently re-opens broken connections, the SDK retries HTTP status codes with backoff. They do not duplicate.Fix: restore OkHttp's default (
retryOnConnectionFailure(true)).Tests: new
SpringAiOpenAiHttpClientTests— one config guard plus one MockWebServer test that reproduces the recovery usingSocketPolicy.DISCONNECT_AT_END. Verified to fail (with the exact issue symptom) if the flag is reverted.