Skip to content

Commit 1daefa3

Browse files
committed
fix: skip first-attempt clock refresh to preserve sync token claim
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent 95a17e9 commit 1daefa3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

services/apps/security_best_practices_worker/src/workflows/triggerSecurityInsightsCheckForRepos.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ export async function triggerSecurityInsightsCheckForRepos(
9999
repoAttemptedTokens.set(repo.repoUrl, attemptedTokens)
100100
}
101101
while (attempts < MAX_TOKEN_ATTEMPTS) {
102-
// Refresh wall-clock time before each token selection. A long-running executeChild can
103-
// block the outer queue loop's refresh for >1h, leaving rate-limit cooldowns stuck when
104-
// this is the only in-flight task (small pool or last repo).
105-
currentTimeMs = await getCurrentTimeMs()
102+
// Refresh wall-clock time on retries only. A long-running executeChild can block the
103+
// outer queue loop's refresh for >1h, leaving rate-limit cooldowns stuck; a per-retry
104+
// refresh fixes that. The first attempt intentionally reuses the outer-loop's
105+
// currentTimeMs so processRepo runs synchronously up to `tokenInfo.inUse = true` —
106+
// otherwise the outer loop can oversubscribe MAX_PARALLEL_CHILDREN tasks against a
107+
// smaller token pool before any inUse mark lands, causing immediate null-token requeues.
108+
if (attempts > 0) {
109+
currentTimeMs = await getCurrentTimeMs()
110+
}
106111
const tokenInfo = getNextToken(tokenInfos, currentTimeMs, attemptedTokens)
107112
if (!tokenInfo) {
108113
// No untried, usable token remains for this repo. Fail only when either every token

0 commit comments

Comments
 (0)