Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 25 additions & 19 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,10 @@ function dumpSarifFile(
fs.writeFileSync(outputFile, sarifPayload);
}

const STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1000;
const STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1000;
// Should lead to status checks after 5s, 15s, 35s, 75s, and 155s.
const STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS = 5 * 1000;
const STATUS_CHECK_BACKOFF_MULTIPLIER = 2;
const STATUS_CHECK_MAX_TRIES = 5;

type ProcessingStatus = "pending" | "complete" | "failed";

Expand All @@ -854,20 +856,15 @@ export async function waitForProcessing(
try {
const client = api.getApiClient();

const statusCheckingStarted = Date.now();
while (true) {
if (
Date.now() >
statusCheckingStarted + STATUS_CHECK_TIMEOUT_MILLISECONDS
) {
// If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
// It's possible the analysis will eventually finish processing, but it's not worth spending more
// Actions time waiting.
logger.warning(
"Timed out waiting for analysis to finish processing. Continuing.",
);
break;
}
// Do an initial wait because processing will always take a minimum of 2-3 seconds
let statusCheckBackoff = STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS;
await util.delay(statusCheckBackoff, { allowProcessExit: false });
Comment on lines +860 to +861
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.


for (
let statusCheckCount = 1;
statusCheckCount <= STATUS_CHECK_MAX_TRIES;
statusCheckCount++
) {
let response: OctokitResponse<any> | undefined = undefined;
try {
response = await client.request(
Expand Down Expand Up @@ -912,9 +909,18 @@ export async function waitForProcessing(
util.assertNever(status);
}

await util.delay(STATUS_CHECK_FREQUENCY_MILLISECONDS, {
allowProcessExit: false,
});
if (statusCheckCount === STATUS_CHECK_MAX_TRIES) {
// If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
// It's possible the analysis will eventually finish processing, but it's not worth spending more
// Actions time waiting.
logger.warning(
"Timed out waiting for analysis to finish processing. Continuing.",
);
break;
} else {
statusCheckBackoff *= STATUS_CHECK_BACKOFF_MULTIPLIER;
await util.delay(statusCheckBackoff, { allowProcessExit: false });
}
}
} finally {
logger.endGroup();
Expand Down
Loading