Skip to content

Change waitForProcessing to use exponential backoff#3937

Open
robertbrignull wants to merge 1 commit into
mainfrom
robertbrignull/waitForProcessing_backoff
Open

Change waitForProcessing to use exponential backoff#3937
robertbrignull wants to merge 1 commit into
mainfrom
robertbrignull/waitForProcessing_backoff

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

The goal is to change waitForProcessing to backoff a bit more aggressively and reduce the maximum number of requests that it makes. During periods where analysis processing is being delayed, we're seeing a large number of extra GET requests that I believe are coming from here. See linked internal issue for more info.

In this PR I'm suggesting changing it to exponential backoff that'll make a maximum of 5 requests, instead of the current behaviour which can make up to 24 requests. I also add a wait before the first poll because processing will always take at least a couple of seconds so it's unlikely that an immediate poll will get anything. Let me know if you think this is reasonable. We can also tweak values to keep the maximum timeout to 2 minutes if that would be better.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Hopefully can be safely tested before merge (either by tests or on a test repository)

Which use cases does this change impact?

Workflow types:

  • Advanced setup - Impacts users who have custom CodeQL workflows.
  • Managed - Impacts users with dynamic workflows (Default Setup, Code Quality, ...).

Products:

  • Code Scanning - The changes impact analyses when analysis-kinds: code-scanning.
  • Code Quality - The changes impact analyses when analysis-kinds: code-quality.
  • Other first-party - The changes impact other first-party analyses.
  • Third-party analyses - The changes affect the upload-sarif action.

Environments:

  • Dotcom - Impacts CodeQL workflows on github.com and/or GitHub Enterprise Cloud with Data Residency.
  • GHES - Impacts CodeQL workflows on GitHub Enterprise Server.

How did/will you validate this change?

  • Test repository - This change will be tested on a test repository before merging.
  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).
  • End-to-end tests - I am depending on PR checks (i.e. tests in pr-checks).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Rollback - Change can only be disabled by rolling back the release or releasing a new version with a fix.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Dashboards - I will watch relevant dashboards for issues after the release. Consider whether this requires this change to be released at a particular time rather than as part of a regular release.
    • Alerts - New or existing monitors will trip if something goes wrong with this change.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

@robertbrignull robertbrignull requested a review from a team as a code owner May 28, 2026 09:54
Copilot AI review requested due to automatic review settings May 28, 2026 09:54
@github-actions github-actions Bot added the size/XS Should be very easy to review label May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR changes SARIF processing polling to use exponential backoff, reducing request volume during delayed analysis processing.

Changes:

  • Replaces fixed 5-second polling with exponential backoff.
  • Adds an initial delay before the first processing-status request.
  • Limits processing-status polling to 5 intended attempts.
Show a summary per file
File Description
src/upload-lib.ts Updates waitForProcessing polling constants and loop behavior to use exponential backoff.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread src/upload-lib.ts Outdated
Comment on lines +922 to +923
statusCheckBackoff *= STATUS_CHECK_BACKOFF_MULTIPLIER;
await util.delay(statusCheckBackoff, { allowProcessExit: false });
Copy link
Copy Markdown
Contributor Author

@robertbrignull robertbrignull May 28, 2026

Choose a reason for hiding this comment

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

I don't think this comment is quite right about the worst case calculations, but it's still a good idea and it would be cleaner to put the timeout check at the end of the loop, instead of doing an extra loop iteration just to break out early.

Comment thread src/upload-lib.ts Outdated
Comment on lines +863 to +868
for (
let statusCheckingCount = 0;
statusCheckingCount <= STATUS_CHECK_MAX_TRIES; // Aborts on the last loop iteration
statusCheckingCount++
) {
if (statusCheckingCount === STATUS_CHECK_MAX_TRIES) {
@github-actions github-actions Bot added size/S Should be easy to review and removed size/XS Should be very easy to review labels May 28, 2026
@robertbrignull robertbrignull force-pushed the robertbrignull/waitForProcessing_backoff branch from e930918 to dfc1411 Compare May 28, 2026 10:15
Copy link
Copy Markdown
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

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

Thanks for preparing this! The change makes to me as-is and there's nothing blocking here.

We may want to review how well chosen the backoff pattern is, but that's something we can adjust later if needed.

Just one comment about the (potential) delay this imposes on the unit tests.

Also agree with Copilot that it would be nice to have a test that checks that this works as expected.

Comment thread src/upload-lib.ts
Comment on lines +860 to +861
let statusCheckBackoff = STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS;
await util.delay(statusCheckBackoff, { allowProcessExit: false });
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.

Minor: I think this also adds a STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS long delay to tests where we can get a "response" from a stubbed client.request faster. If that is the case, we could either make this initial wait conditional on e.g. the NODE_ENV (like in #3930) or stub util.delay in relevant tests to not wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Should be easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants