Skip to content

Add rate limiting and retry logic to source map uploads#10191

Merged
andrewbrook merged 1 commit into
crashlyticsfrom
crash2
Mar 31, 2026
Merged

Add rate limiting and retry logic to source map uploads#10191
andrewbrook merged 1 commit into
crashlyticsfrom
crash2

Conversation

@andrewbrook
Copy link
Copy Markdown
Contributor

Description

Limits in-flight requests to upload/register source maps, and adds a retry with backoff

Scenarios Tested

Manual, unit tests

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces concurrency limiting and retry logic for Crashlytics source map uploads, along with improved error handling for 409 conflict responses. Feedback was provided to extract the retry logic into a helper function to ensure consistency between single-file and directory upload paths while reducing code duplication.

Comment on lines +122 to +128
let success = await uploadMap(request, 1);
if (!success) {
// Wait 5s and retry
await new Promise((res) => setTimeout(res, (options.retryDelay as number) || 5000));
success = await uploadMap(request);
}
return success;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This retry logic is a great addition for handling transient errors. However, it's currently only applied when uploading source maps from a directory. For consistency, the same logic should be applied when uploading a single source map file (in the if (fstat.isFile()) block around line 86).

To avoid code duplication and improve maintainability, you could extract this retry logic into a helper function. This aligns with the repository's best practice of using helper functions to encapsulate branching logic.

For example:

async function uploadMapWithRetry(request: UploadRequest, options: CommandOptions): Promise<boolean> {
  let success = await uploadMap(request, 1);
  if (!success) {
    // Wait and retry
    await new Promise((res) => setTimeout(res, (options.retryDelay as number) || 5000));
    success = await uploadMap(request);
  }
  return success;
}

You could then use this helper in both the single file and directory upload scenarios.

References
  1. The style guide recommends using helper functions to encapsulate branching logic and reduce nesting. (link)

@andrewbrook andrewbrook merged commit 0b1d040 into crashlytics Mar 31, 2026
43 checks passed
@andrewbrook andrewbrook deleted the crash2 branch March 31, 2026 13:24
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