Skip to content

feat: support auto retry for http requests - #198

Merged
cre8ivejp merged 41 commits into
masterfrom
chore/retry-on-499
Jun 17, 2026
Merged

feat: support auto retry for http requests#198
cre8ivejp merged 41 commits into
masterfrom
chore/retry-on-499

Conversation

@duyhungtnn

@duyhungtnn duyhungtnn commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

#199
This pull request introduces a robust and configurable retry mechanism for HTTP requests, including support for the Retry-After header, exponential backoff with jitter, and comprehensive configuration validation and defaults. It also adds extensive unit tests to ensure correct parsing and propagation of retry-related logic throughout the codebase.

Retry logic and error handling improvements:

  • Added a new promiseRetriable utility in src/utils/promiseRetriable.ts that provides generic, configurable retry logic with exponential backoff and jitter, as well as logic to respect the Retry-After header and classify retryable errors and status codes.
  • Enhanced the InvalidStatusError class in src/objects/errors.ts to include an optional retryAfterMs property, and added a parseRetryAfter function to parse both delta-seconds and HTTP-date formats from the Retry-After header.
  • Updated the HTTP client in src/api/client.ts to parse the Retry-After header from error responses and propagate it via InvalidStatusError, ensuring that retry logic can use this information. [1] [2]

Configuration:

  • Default flush interval change (10s → 30s)
  • Introduced new retry-related configuration options (maxRetries, retryInitialInterval, retryMaxInterval) to the BKTConfig interface in src/config.ts, with sensible defaults and validation logic to handle negative or inconsistent values. [1] [2] [3] [4] [5]
  • Retry is ON by default.

Validation:

  • Updated test configuration helpers and conversion logic to reflect and test these new retry options. [1] [2] [3]

@duyhungtnn duyhungtnn changed the title feat: add promiseRetriable utility and tests chore: add retry configuration options for http requests Apr 15, 2026
@duyhungtnn
duyhungtnn force-pushed the chore/retry-on-499 branch from 53c21ca to 155bd57 Compare May 31, 2026 15:08
@duyhungtnn
duyhungtnn requested a review from Copilot June 4, 2026 10:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable HTTP retry behavior to the Bucketeer Node server SDK, wiring retry policy from configuration into the API client and introducing per-call abort/deadlines to keep polling and request lifecycles bounded.

Changes:

  • Introduces a generic promiseRetriable utility (exponential backoff + jitter + Retry-After support) and threads retry metadata via InvalidStatusError.retryAfterMs.
  • Adds retry-related config fields (maxRetries, retryInitialInterval, retryMaxInterval, retryMultiplier) with defaults/validation and propagates them into APIClient.
  • Adds abort-signal based cancellation for polling and key calls, plus extensive unit tests for retry/backoff, Retry-After parsing, and polling cancellation.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.test.json Ensures test compilation includes src/**/*.
src/utils/promiseRetriable.ts New retry helper with backoff/jitter and retryability classification.
src/utils/pollController.ts New helper to create/replace polling-bound abort signals.
src/objects/errors.ts Adds parseRetryAfter and InvalidStatusError.retryAfterMs.
src/index.ts Builds retry policy from resolved config and passes it to APIClient.
src/config.ts Adds retry config fields, defaults, and validation logic.
src/client.ts Adds per-call timeouts via AbortSignal.timeout(...) for key API calls.
src/cache/processor/segmentUsersCacheProcessor.ts Uses PollController signal to bound/cancel polling requests.
src/cache/processor/featureFlagCacheProcessor.ts Uses PollController signal to bound/cancel polling requests.
src/api/client.ts Adds retry wrapper and Retry-After parsing/propagation in HTTP errors.
src/tests/promise_retriable.ts Unit tests for retry behavior, backoff, status/network retryability, and abort support.
src/tests/poll_controller.ts Unit tests for PollController behavior.
src/tests/parse_retry_after.ts Unit tests for Retry-After parsing and retryAfterMs property.
src/tests/mocks/api.ts Updates mock API client signatures to accept optional AbortSignal.
src/tests/define_bkt_config.ts Adds tests for retry config defaults/validation.
src/tests/convert_config_to_bkt_config.ts Verifies deprecated config conversion includes retry defaults.
src/tests/client.ts Adjusts test to avoid retryable 5xx behavior impacting runtime.
src/tests/client_graceful_shutdown.ts Updates test config to include retry fields.
src/tests/client_graceful_shutdown_batching.ts Updates test config to include retry fields.
src/tests/client_get_evaluation_metrics_events.ts Updates test config to include retry fields.
src/tests/cache/processor/segementUsersCache/init.ts Updates expectations for new AbortSignal parameter.
src/tests/cache/processor/featureCache/polling.ts Updates expectations for new AbortSignal parameter.
src/tests/cache/processor/featureCache/init.ts Updates expectations for new AbortSignal parameter.
src/tests/api_retry_after.ts Adds integration-style tests asserting Retry-After propagation.
ava-test.config.mjs Sets a global AVA timeout of 30s.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/client.ts Outdated
Comment thread src/utils/promiseRetriable.ts
Comment thread src/config.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 7 comments.

Comment thread src/config.ts Outdated
Comment thread src/api/client.ts
Comment thread src/api/client.ts
Comment thread src/config.ts
Comment thread src/config.ts
Comment thread src/config.ts
Comment thread src/config.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Comment thread src/__tests__/api_retry.ts
Comment thread src/__tests__/api_retry_after.ts
Comment thread src/cache/processor/featureFlagCacheProcessor.ts
Comment thread src/cache/processor/segmentUsersCacheProcessor.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.

Comment thread src/objects/metricsEvent.ts
Comment thread src/config.ts
Comment thread src/api/client.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.

Comment thread src/api/client.ts
Comment thread src/config.ts
Comment thread Makefile Outdated
@duyhungtnn duyhungtnn changed the title chore: add retry configuration options for http requests chore: support retry options for http requests Jun 7, 2026
@duyhungtnn
duyhungtnn requested a review from Copilot June 7, 2026 14:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.

Comment thread src/api/client.ts
Comment thread src/config.ts
Comment thread src/__tests__/client.ts Outdated
Comment thread src/config.ts
Comment thread src/__tests__/cache/processor/featureCache/cancellation.ts Outdated
Comment thread src/__tests__/cache/processor/segementUsersCache/cancellation.ts Outdated
Comment thread src/__tests__/cache/processor/segementUsersCache/cancellation.ts Outdated
@duyhungtnn
duyhungtnn marked this pull request as ready for review June 11, 2026 16:07
@duyhungtnn
duyhungtnn requested a review from cre8ivejp as a code owner June 11, 2026 16:07
@duyhungtnn
duyhungtnn marked this pull request as draft June 12, 2026 01:37
Update DEFAULT_FLUSH_INTERVAL_MILLIS from 10_000 to 30_000 and revise comments to clarify that the minimum flush interval remains 10s while the default is 30s. This ensures the default flush cadence is less frequent than the enforced minimum and makes intent explicit in the code comments.
Config validation now rejects zero (previously only negative) and
resets to the 1 s default with a warning, matching Go SDK behavior.
calculateBackoff also enforces the same floor as defense-in-depth,
so bypassing config cannot produce zero-delay retries.
@duyhungtnn
duyhungtnn force-pushed the chore/retry-on-499 branch from 6ff8e2d to 00759f1 Compare June 17, 2026 04:55

@cre8ivejp cre8ivejp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@cre8ivejp cre8ivejp changed the title chore: support retry options for http requests feat: support auto retry for http requests Jun 17, 2026
@cre8ivejp
cre8ivejp merged commit 1cd775a into master Jun 17, 2026
9 checks passed
@cre8ivejp
cre8ivejp deleted the chore/retry-on-499 branch June 17, 2026 08:36
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.

3 participants