Skip to content

Retry policy (§9 partial) + executeSync cancellation handling#6

Merged
MarketDataDev03 merged 3 commits into
mainfrom
06_retry_policies
May 13, 2026
Merged

Retry policy (§9 partial) + executeSync cancellation handling#6
MarketDataDev03 merged 3 commits into
mainfrom
06_retry_policies

Conversation

@MarketDataDev03

Copy link
Copy Markdown
Collaborator

Retry policy (§9 partial) + executeSync cancellation handling

Implements 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 (executeSync not catching CancellationException), which is no longer purely latent now that retry can cancel internal futures.

Summary

  • Retry/backoff: 3 attempts, min(1s × 2^N, 30s) exponential. Retries 501–599 and NetworkError with an IOException-shaped cause; never retries 500, 4xx, 429, ParseError, or sync-thrown bugs. Uses CompletableFuture.delayedExecutor so no extra threads are introduced.
  • Cancellation discipline: caller cancellation of the returned CompletableFuture bails 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).
  • Issue implement /v1/markets/status/ endpoint + integration testing pipeline #2 closed: executeSync now catches CancellationException alongside CompletionException and routes it through asRuntime.

What changed

New file — RetryPolicy.java

Package-private. Two responsibilities:

  • shouldRetry(Throwable cause, int attempt) — true for NetworkError(cause = IOException…) and ServerError(status ∈ [501, 599]), false for everything else. Caps at maxAttempts.
  • backoffDelay(int attempt)min(initial × 2^N, maxBackoff), with explicit guards against 1L << ≥63 silent wrap-around and against base * multiplier overflow.

The constructor accepts custom values; tests use sub-millisecond delays so they don't add wall-clock to the suite.

HttpTransport.java

  • New package-private constructor with a RetryPolicy parameter for tests; the existing constructors default to RetryPolicy.defaults().
  • executeAsync now orchestrates retries via a recursive attempt() method scheduled on CompletableFuture.delayedExecutor. The original single-shot logic moved to executeOnce.
  • Single cascade-cancel handler: one result.whenComplete installed in executeAsync plus an AtomicReference<CompletableFuture<T>> currentDispatched tracks 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.)
  • executeSync catches CancellationException and routes through asRuntime (Issue implement /v1/markets/status/ endpoint + integration testing pipeline #2).

@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

The author of this PR, MarketDataDev03, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at support@codecov.io with any questions.

Base automatically changed from 01_endpoint_v1_markets_status to main May 12, 2026 19:12
@MarketDataDev03 MarketDataDev03 marked this pull request as ready for review May 12, 2026 19:20
@MarketDataDev03 MarketDataDev03 self-assigned this May 12, 2026
@MarketDataDev03 MarketDataDev03 merged commit 6727439 into main May 13, 2026
5 checks passed
@MarketDataDev03 MarketDataDev03 deleted the 06_retry_policies branch June 9, 2026 18:56
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