Retry policy (§9 partial) + executeSync cancellation handling#6
Merged
Conversation
|
The author of this PR, MarketDataDev03, is not an activated member of this organization on Codecov. |
MarketDataDev01
approved these changes
May 13, 2026
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.
Retry policy (§9 partial) +
executeSynccancellation handlingImplements the retry/backoff half of SDK requirements §9 on top of the request layer that landed in
01_endpoint_v1_markets_status. Network errors and HTTP 501–599 now retry with exponential backoff; everything else surfaces immediately. Also closes Issue #2 of the 2026-05-11 review (executeSyncnot catchingCancellationException), which is no longer purely latent now that retry can cancel internal futures.Summary
min(1s × 2^N, 30s)exponential. Retries 501–599 andNetworkErrorwith anIOException-shaped cause; never retries 500, 4xx, 429,ParseError, or sync-thrown bugs. UsesCompletableFuture.delayedExecutorso no extra threads are introduced.CompletableFuturebails out of any pending backoff and propagates to the in-flight attempt (which in turn cancels the semaphore waiter — Issue initial Market Data Java SDK scaffold + CI #1's fix continues to hold across the retry-loop indirection).executeSyncnow catchesCancellationExceptionalongsideCompletionExceptionand routes it throughasRuntime.What changed
New file —
RetryPolicy.javaPackage-private. Two responsibilities:
shouldRetry(Throwable cause, int attempt)— true forNetworkError(cause = IOException…)andServerError(status ∈ [501, 599]), false for everything else. Caps atmaxAttempts.backoffDelay(int attempt)—min(initial × 2^N, maxBackoff), with explicit guards against1L << ≥63silent wrap-around and againstbase * multiplieroverflow.The constructor accepts custom values; tests use sub-millisecond delays so they don't add wall-clock to the suite.
HttpTransport.javaRetryPolicyparameter for tests; the existing constructors default toRetryPolicy.defaults().executeAsyncnow orchestrates retries via a recursiveattempt()method scheduled onCompletableFuture.delayedExecutor. The original single-shot logic moved toexecuteOnce.result.whenCompleteinstalled inexecuteAsyncplus anAtomicReference<CompletableFuture<T>> currentDispatchedtracks the current attempt. Cancelling the returned future cancels whichever attempt is in flight; previous attempts in the chain are already done by the time the reference is updated. (Earlier draft attached a fresh handler per attempt — feedback-fixed.)executeSynccatchesCancellationExceptionand routes throughasRuntime(Issue implement /v1/markets/status/ endpoint + integration testing pipeline #2).