fix(sdk): Add comprehensive retry logic with exponential backoff for network failures - #256
Open
Vincent6581 wants to merge 2 commits into
Open
fix(sdk): Add comprehensive retry logic with exponential backoff for network failures#256Vincent6581 wants to merge 2 commits into
Vincent6581 wants to merge 2 commits into
Conversation
Adds a transient-failure retry layer:
- RetryConfig (maxRetries, baseDelayMs, maxDelayMs, backoffMultiplier,
jitter) with DEFAULT_RETRY_CONFIG
- classifyError() / isRetryableError() distinguishing transient failures
(network timeouts, socket errors, HTTP 408/425/429/5xx, Horizon 504,
mempool full, retryable Stellar result codes) from deterministic ones
(invalid signature, insufficient funds, contract errors, unauthorized,
invalid parameters, KYC/compliance failures)
- computeRetryDelay() — capped exponential backoff with bounded jitter
- withRetry(fn, options) — honours Retry-After on RateLimitError, an
optional abort signal, and injectable sleep/rng for testing
- RetryEvent stream ('retry' | 'exhausted' | 'succeeded') via
onRetryEvent for UI feedback
- New RateLimitError / MempoolFullError classes
- StellarRWASDK.withRetry() + StellarRWASDK.onRetry() using a per-SDK
retryConfig (configurable via new config.retry)
- Constants: RETRYABLE_HTTP_STATUS_CODES, RETRYABLE_NETWORK_ERROR_CODES,
RETRYABLE_STELLAR_RESULT_CODES, RETRYABLE_ERROR_MESSAGE_PATTERNS
Also repairs a pre-existing syntax error in the SUGGESTED_ACTIONS map
(TX_BAD_SEQ key) and a missing ParsedHorizonError type import that the
syntax error had been masking.
Files:
- sdk/src/errors.ts
- sdk/src/constants.ts
- sdk/src/index.ts
Closes Kevin737866#191
|
@Vincent6581 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
@Vincent6581 cconflict |
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.
Summary
Adds an intelligent retry layer for transient network failures, per issue #191. Deterministic failures are never retried.
Acceptance criteria
RetryConfig: maxRetries, baseDelayMs, maxDelayMs, backoffMultiplierjitter;DEFAULT_RETRY_CONFIGinconstants.tsETIMEDOUT,ECONNRESET, …), HTTP408/425/429/500/502/503/504,mempool is full/ rate-limit message patterns, retryable Stellar result codes (tx_too_late,tx_bad_seq, …)UNAUTHORIZED,INVALID_PARAMETERS, KYC/compliance,tx_bad_auth,op_*, any 4xxRetryEvent(retry/exhausted/succeeded) viaonRetryEvent, orsdk.onRetry(listener)Public API
Or via the SDK instance:
Design notes
classifyError(error)returns{ retryable, reason }— thereasonstring is handy for logs/telemetry.isRetryableError()wraps it.min(maxDelayMs, baseDelayMs * multiplier^index)then± jitter.sleepandrngare injectable so backoff timing is deterministic under test; aRateLimitError.retryAfterMsraises the floor of the next delay.{ aborted: boolean }signal stops further retries between attempts.Incidental fix
errors.tshad a syntax error in theSUGGESTED_ACTIONSmap ([ErrorCode.TX_BAD_SEQ'— stray quote) that prevented the module from compiling at all; that also masked a missingParsedHorizonErrortype import. Both are fixed here since the file is being modified.Files changed
sdk/src/errors.ts— retry classification, backoff,withRetry, new error classessdk/src/constants.ts— retry config + retryable code/pattern tablessdk/src/index.ts— exports;StellarRWASDK.withRetry()/.onRetry()/config.retryCloses #191