Skip to content

Commit eb28875

Browse files
committed
fix(cli): retry mechanism when multiple systems query the MAPI
When multiple systems hit the MAPI with the same access token, the retry mechanisms quickly gave up. By decreasing the semaphore queue size and increasing the max retries, we make such situations less likely. However, it is still possible to run into limits when many systems query the MAPI with the same access token in parallel.
1 parent d570a6c commit eb28875

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

packages/cli/src/commands/migrations/run/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ migrationsCommand.command('run [componentName]')
114114
query,
115115
starts_with: startsWith,
116116
},
117-
batchSize: 100,
117+
batchSize: 6,
118118
onTotal: (total) => {
119119
storiesProgress.setTotal(total);
120120
migrationsProgress.setTotal(total);
@@ -141,7 +141,7 @@ migrationsCommand.command('run [componentName]')
141141
space,
142142
publish,
143143
dryRun,
144-
batchSize: 100,
144+
batchSize: 6,
145145
onProgress: () => {
146146
updateProgress.increment();
147147
},

packages/mapi-client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ The client includes built-in retry handling for rate limits and network errors:
140140

141141
```typescript
142142
// The client automatically handles retries with these defaults:
143-
// - maxRetries: 3
143+
// - maxRetries: 12
144144
// - retryDelay: 1000ms
145145
// - Respects retry-after headers from 429 responses
146146

147147
const stories = await client.stories.list({
148148
path: { space_id: 123456 },
149149
query: { per_page: 10 }
150150
});
151-
// If rate limited, will automatically retry up to 3 times
151+
// If rate limited, will automatically retry up to 12 times
152152
```
153153

154154
## Runtime Configuration

packages/mapi-client/src/__tests__/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ describe('ManagementApiClient Integration - Per-Instance Rate Limiting', () => {
107107

108108
const result = await promise;
109109

110-
// Should make initial + maxRetries calls (3 retries = 4 total)
111-
expect(mockFetch).toHaveBeenCalledTimes(4);
110+
// Should make initial + maxRetries calls (12 retries = 13 total)
111+
expect(mockFetch).toHaveBeenCalledTimes(13);
112112

113113
// Result should contain the error since all retries failed
114114
expect(result).toBeDefined();

packages/mapi-client/src/client/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const createClient = (config: Config): Client => {
9090

9191
// Execute with retry logic by recreating the request for each attempt
9292
let response = await executeWithRetry(_fetch, url, requestInit, {
93-
maxRetries: 3,
93+
maxRetries: 12,
9494
retryDelay: 1000
9595
});
9696

@@ -206,7 +206,8 @@ export const createClient = (config: Config): Client => {
206206

207207
if (response.status === 429 && attempt < retryConfig.maxRetries) {
208208
const retryAfter = response.headers.get('retry-after');
209-
const delay = retryAfter ? parseInt(retryAfter) * 1000 : retryConfig.retryDelay;
209+
const backoff = retryConfig.retryDelay * (attempt + 1);
210+
const delay = retryAfter ? parseInt(retryAfter) * 1000 : backoff;
210211

211212
await new Promise(resolve => setTimeout(resolve, delay));
212213

0 commit comments

Comments
 (0)