You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
10
18
11
-
## Max retry attempts
19
+
## Retry Strategy
12
20
13
-
The default maximum number of retries in case of failed API call is 5.
14
-
To change this number you should initialize `BoxRetryStrategy` with the new value and pass it to `NetworkSession`.
21
+
### Overview
22
+
23
+
The SDK ships with a built-in retry strategy (`BoxRetryStrategy`) that implements the `RetryStrategy` interface. The `BoxNetworkClient`, which serves as the default network client, uses this strategy to automatically retry failed API requests with exponential backoff.
24
+
25
+
The retry strategy exposes two methods:
26
+
27
+
-**`should_retry`** — Determines whether a failed request should be retried based on the HTTP status code, response headers, attempt count, and authentication state.
28
+
-**`retry_after`** — Computes the delay (in seconds) before the next retry attempt, using either the server-provided `Retry-After` header or an exponential backoff formula.
|`max_attempts`|`5`| Maximum number of retry attempts for HTTP error responses (status 4xx/5xx). |
35
+
|`retry_base_interval`|`1` (second) | Base interval used in the exponential backoff calculation. |
36
+
|`retry_randomization_factor`|`0.5`| Jitter factor applied to the backoff delay. The actual delay is multiplied by a random value between `1 - factor` and `1 + factor`. |
37
+
|`max_retries_on_exception`|`2`| Maximum number of retries for network-level exceptions (connection failures, timeouts). These are tracked by a separate counter from HTTP error retries. |
38
+
39
+
### Retry Decision Flow
40
+
41
+
The following diagram shows how `BoxRetryStrategy.should_retry` decides whether to retry a request:
When the server includes a `Retry-After` header in the response, the SDK uses the header value directly as the delay in seconds instead of computing an exponential backoff delay. This applies to any retryable response that includes the header, including:
115
+
116
+
-`202 Accepted` with `Retry-After` (long-running operations)
117
+
-`429 Too Many Requests` with `Retry-After`
118
+
-`5xx` server errors with `Retry-After`
119
+
120
+
The header value is parsed as a floating-point number representing seconds.
121
+
122
+
### Network Exception Handling
123
+
124
+
Network-level failures (connection refused, DNS resolution errors, timeouts, TLS errors) are represented internally as responses with status `0`. These exceptions are tracked by a **separate counter** (`max_retries_on_exception`, default `2`) from the regular HTTP error retry counter (`max_attempts`).
125
+
126
+
This means:
127
+
128
+
- Network exception retries are tracked independently from HTTP error retries, each with their own counter and backoff progression.
129
+
- A request can fail up to `max_retries_on_exception` times due to network exceptions, but each exception retry also increments the overall attempt counter, so the total number of retries across both exception and HTTP error types is bounded by `max_attempts`.
130
+
131
+
### Customizing Retry Parameters
132
+
133
+
You can customize all retry parameters by initializing `BoxRetryStrategy` with the desired values and passing it to `NetworkSession`:
0 commit comments