Skip to content

MLE-32953: Do not resend a one-shot request after a 502, 503 or 504 - #2002

Open
prgs-rsingh wants to merge 1 commit into
developfrom
MLE-32953-one-shot-retry
Open

prgs-rsingh wants to merge 1 commit into
developfrom
MLE-32953-one-shot-retry

Conversation

@prgs-rsingh

Copy link
Copy Markdown

Problem

The client sends a request again after a 502, 503 or 504. Several calls did not check whether the content of the request could be read again:

  • an Optic plan with bound content, including bindParam(…, DocumentWriteSet);
  • values(), search() and match() with a raw query;
  • match() with a document.

Content that can only be read once, such as an InputStreamHandle, had been consumed by the attempt that failed, so the request was sent again without it. An Optic write() of InputStreamHandle documents could store empty documents this way, with no error. A Reader failed with Stream closed instead.

This predates #1995 and was raised in its review. It is a follow-up to #1995, which made isOneShot() reliable for every request body and is what makes a single check possible.

Changes

  • OkHttpServices.throwIfRequestCannotBeSentAgain throws a ResourceNotResendableException when the body of a request that was answered with 502, 503 or 504 is one-shot. It is called from sendRequestWithRetry, which covers the Optic, values() and match(document) calls, and from the retry loops of search() and match(QueryDefinition), which have loops of their own.
  • In sendRequestWithRetry the check runs after a caller's own check, so callers that already had one report the same message as before.
  • The message names the path of the request, not its query string.

Behavior changes

  • A one-shot request that is answered with 502, 503 or 504 fails with a ResourceNotResendableException in the calls listed above, as a document write already did. These calls used to send the request again without its content.
  • Content that can be read again is still sent again, within the usual retry limits.
  • OutputStreamHandle counts as one-shot unless setResendable(true) is called on it. An application that uses one in these calls with a sender that can write its content repeatedly has to call that to keep the retry.

Tests

OneShotRequestRetryTest uses a mock server that answers the first request with a retryable status. 25 tests:

  • Each of the six calls is not sent again when its content is one-shot.
  • The same for a Reader, for an OutputStreamHandle, and for one one-shot document among resendable ones.
  • Each of 502, 503 and 504, for one-shot and for resendable content.
  • What must not change:
    • resendable content and a request without a body are sent again, also until the retry period has elapsed;
    • a document write and a Data Services call keep their own check;
    • a request in a transaction and a status that is not retried are reported as before;
    • with digest authentication, the next one-shot request is preceded by a ping again.

With the check disabled, the 13 tests that expect a one-shot request not to be sent again fail.

Run locally together with StreamingPartRequestTest, StreamingOutputImplTest, ChunkedGzipConnectionCloseInterceptorTest and OkHttpUtilConnectionPoolTest: 48 tests pass. The tests that need MarkLogic were not run locally.

The client sends a request again after a 502, 503 or 504. Content that
can only be read once had been consumed by the attempt that failed, so
the request was sent again without it. An Optic plan that writes
documents from an InputStreamHandle could store empty documents this
way, without an error.

- sendRequestWithRetry and the retry loops of search() and
  match(QueryDefinition) now throw a ResourceNotResendableException
  when the body of the failed request is one-shot. This covers the
  callers that had no check of their own: Optic plans with bound
  content, values() with a raw query, match() with a document, and
  search() and match() with a raw query.
- Content that can be read again is still sent again.
- OneShotRequestRetryTest covers each of these with a mock server, for
  each retryable status, along with the cases that must not change: a
  caller with a check of its own, a request without a body, a request
  in a transaction, a status that is not retried, an OutputStreamHandle
  marked as resendable, a resendable request while the server stays
  unavailable, and the ping before the next one-shot request
  with digest authentication.

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change preventing retries of consumed one-shot request bodies.

No open issues 🎉

What changed in this PR

Prevents the Java client from resending consumed, one-shot request bodies after HTTP 502, 503, or 504 responses, building on #1995’s reliable isOneShot() detection.

Changes:

  • Adds a shared resendability check to the common retry path and separate search/match loops.
  • Preserves caller-specific checks and retries for resendable content.
  • Adds regression tests covering streaming handles, retry statuses, transactions, and digest authentication.
File Description
marklogic-client-api/​src/​test/​java/​com/​marklogic/​client/​impl/​OneShotRequestRetryTest.java Tests one-shot rejection and existing retry behavior.
marklogic-client-api/​src/​main/​java/​com/​marklogic/​client/​impl/​OkHttpServices.java Rejects retries when the sent request body is one-shot.

Review effort: Balanced

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.

2 participants