Repository navigation
MLE-32953 Send Connection: close on gzipped rows requests - #1995
Draft
prgs-rsingh wants to merge 3 commits into
Draft
prgs-rsingh wants to merge 3 commits into
prgs-rsingh wants to merge 3 commits into
Conversation
…ndability StreamingOutputImpl previously hardcoded isRetryable()=false / isOneShot()=true for every wrapped OutputStreamSender, even when the originating write handle was fully buffered and resendable (e.g. JacksonHandle, StringHandle). This meant any request body built from such a handle -- including Row Manager plan execution, document writes, and Data Services parameters -- was needlessly blocked from being retried by RetryIOExceptionInterceptor after a transient connection error, even though the content could safely be written again. Thread each call site's already-known isResendable()/handleBase.isResendable() value into StreamingOutputImpl instead of assuming non-resendable: - writeDocumentImpl-style document writes - putPostValueImpl - postResource / putResource (used by RowManagerImpl for Optic plan execution) - postIteratedResourceImpl (multipart-mixed eval/invoke style resources) - addParts multipart builder - makeRequestBodyForContent and BaseProxy's makeRequestBody (Data Services single-node parameters) Call sites without an existing resendable concept (structured query search, alert match) keep the prior conservative false/one-shot default via new 3-arg doPost/doPut overloads, so behavior is unchanged where resendability was never determined. Added StreamingOutputImplTest cases covering: a resendable body being retried after a simulated connection failure, and a non-resendable part inside a MultipartBody still propagating isOneShot()=true so it is never retried. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The change ignores legacy retry opt-outs and uploads one-shot bodies after unsuccessful preflight retries, risking resends of consumed content and ResourceNotResendableException failures.
2 open issues
What changed in this PR
This PR addresses connection reuse and one-shot request handling in the core Java client, aiming to prevent failed uploads after MarkLogic closes a gzip-enabled rows connection.
Changes:
- Adds a network interceptor that requests connection closure for gzip responses with trailers.
- Uses OkHttp’s
isOneShot()contract for retry decisions and centralizes digest-authentication preflight pings. - Closes buffered multipart responses promptly and adds streaming-request regression tests.
| File | Description |
|---|---|
marklogic-client-api/src/test/java/com/marklogic/client/impl/StreamingPartRequestTest.java |
Adds connection reuse, streaming failure, and digest-authentication tests. |
marklogic-client-api/src/test/java/com/marklogic/client/impl/StreamingOutputImplTest.java |
Tests handle resendability and multipart retry behavior. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/StreamingOutputImpl.java |
Reports one-shot status from handle resendability. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java |
Centralizes body construction and preflight pings; closes buffered responses. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/RetryIOExceptionInterceptor.java |
Uses one-shot status to bypass retries. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/RetryableRequestBody.java |
Deprecates the legacy retry contract. |
marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/ChunkedGzipConnectionCloseInterceptor.java |
Adds the gzip/trailers connection-close workaround. |
Review effort: Balanced
| RequestBody requestBody = request.body(); | ||
|
|
||
| if (request.body() instanceof RetryableRequestBody body && !body.isRetryable()) { | ||
| if (requestBody != null && requestBody.isOneShot()) { |
| pingDelay = pingServer(baseUri, "ping", 0); | ||
| } | ||
| if (pingDelay > 0) { | ||
| logger.warn("Server still unavailable after {} ping attempts before sending a one-shot request", maxPingRetries); |
prgs-rsingh
force-pushed
the
MLE-32953-connection-close
branch
from
November 24, 2026 04:41
a41b4a6 to
d100c10
Compare
MarkLogic answers a request that has both "TE: trailers" and "Accept-Encoding: gzip" (every /v1/rows call) with a chunked, gzipped response marked "Connection: Keep-Alive", and then closes the connection. OkHttp reuses that dead connection, so a following request with a one-shot body (e.g. a Reader) fails and cannot be resent. A Data Services call with a streaming parameter, made right after RowManager.resultRows(), failed this way with "Stream closed". - ChunkedGzipConnectionCloseInterceptor adds "Connection: close" to such requests on HTTP/1.1, so OkHttp does not pool the connection. This is a workaround until the server bug is fixed. - Every request body is built by toRequestBody, so isOneShot() always reflects the handle's isResendable(), also inside a MultipartBody. OkHttp and RetryIOExceptionInterceptor then never resend a consumed body. RetryableRequestBody is deprecated; RetryIOExceptionInterceptor still honors it for bodies that do not override isOneShot(). - With digest authentication, a body-less ping takes the 401 challenge before the first one-shot request on a thread. This is now done in sendRequestOnce, so it covers every call path. If the server is still unavailable after the ping retries, the request fails with a FailedRetryException instead of sending a body that would be lost. StreamingPartRequestTest and ChunkedGzipConnectionCloseInterceptorTest use a mock server. StreamingOutputImplTest checks isOneShot() for each handle type.
prgs-rsingh
force-pushed
the
MLE-32953-connection-close
branch
from
November 24, 2026 04:48
d100c10 to
10c78a5
Compare
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.


Problem
A Data Services call with a streaming parameter (for example a
Reader) fails intermittently when it follows a Row Manager query.MarkLogic answers a request that has both
TE: trailersandAccept-Encoding: gzipwith a chunked, gzipped response markedConnection: Keep-Alive, and then closes the connection. Every/v1/rowscall from this client sends both headers. OkHttp puts the dead connection back in its pool, so the next request on it fails. A request with a one-shot body cannot be resent, so the call fails.This is a MarkLogic server bug, raised separately. The change here is a client workaround until the server is fixed.
Changes
ChunkedGzipConnectionCloseInterceptoraddsConnection: closeto HTTP/1.1 requests that have both headers, so OkHttp does not pool the connection. The server closes that connection anyway, so no connection reuse is lost. It is a network interceptor so that it sees the headers that are actually sent, including when gzip is disabled withRemoveAcceptEncodingConfigurator.toRequestBody, soisOneShot()always reflects the handle'sisResendable(), also inside aMultipartBody. OkHttp andRetryIOExceptionInterceptorthen never resend a consumed body, and the real failure is reported instead ofStream closed.RetryableRequestBodyis deprecated;RetryIOExceptionInterceptorstill honors it for bodies that do not overrideisOneShot().sendRequestOnce, so it covers every call path. If the server is still unavailable after the ping retries, the request fails with aFailedRetryExceptioninstead of sending a body that would be lost.Tests
StreamingPartRequestTest(mock server): a streaming request after a rows request succeeds; the connection is kept when gzip is disabled; a failed streaming request is not resent; digest authentication pings only before the first streaming request; a streaming request is not sent when the pings find the server unavailable.ChunkedGzipConnectionCloseInterceptorTest(mock server): an HTTP/1.1 connection is not reused, an HTTP/2 connection is.StreamingOutputImplTest:isOneShot()for each handle type and for multipart bodies; a body that only implements the deprecatedRetryableRequestBodyis still not retried.Notes
xdmp:set-response-chunked-encoding(true)cannot be detected from the request headers.