Skip to content

fix: stop refresh cycle when GitHub rate limit is reached#134

Closed
CodeMatrix1 wants to merge 1 commit intoRocketChat:masterfrom
CodeMatrix1:fix/stop-refresh-on-github-rate-limit
Closed

fix: stop refresh cycle when GitHub rate limit is reached#134
CodeMatrix1 wants to merge 1 commit intoRocketChat:masterfrom
CodeMatrix1:fix/stop-refresh-on-github-rate-limit

Conversation

@CodeMatrix1
Copy link
Copy Markdown

@CodeMatrix1 CodeMatrix1 commented Mar 28, 2026

Summary

Stops the current refresh cycle when the GitHub API rate limit is reached, instead of continuing to issue requests for the remaining contributors in the same run.

This keeps the server alive, but avoids wasting requests and producing repeated skip/warning noise after rate limiting has already been detected.

Motivation

Once the GitHub API rate limit is exhausted, the current refresh loop continues processing contributors even though the remaining requests in that cycle are very likely to fail.

That leads to:

  • unnecessary API calls
  • repeated warning spam
  • more skipped contributors
  • confusing logs during local debugging and production operation

This change makes the refresh behavior more intentional: stop the current cycle early and wait for the next scheduled run.

Changes (high level)

src/server/util/API.js

  • Adds a small internal rateLimitExceeded flag
  • Sets that flag when GitHub returns an API rate limit exceeded message
  • Exposes:
    • isRateLimitExceeded()
    • resetRateLimitExceeded()

src/server/refresh.js

  • Resets the rate-limit flag at the start of each refresh cycle
  • Checks the flag before processing each contributor
  • Stops the current cycle early once the flag is set
  • Awaits each contributor fetch inside Promise.mapSeries(...) so requests complete sequentially and the stop behavior applies cleanly
  • Logs:
    • [WARNING] Refresh cycle stopped because the GitHub API rate limit was reached.

Why this is different from existing rate-limit logging

The existing API error handling logs the rate-limit message and returns from the individual request helper.

This change goes further by:

  • tracking that the cycle has hit rate limiting
  • stopping the remaining contributor processing for the current refresh run

Tests

  1. testing the functionality by forcing early stop before any contributor is pulled from github (not done in the fix)
image

process doesnt exit above, only execution stops(did'nt know what to do)

  1. npm test
image

No automated tests were added for this change since enough e2e support is lacking.

AI-assisted contribution disclosure - Mostly AI-generate

How to verify

NODE_OPTIONS=--openssl-legacy-provider npm run build
cd dist/server
node app.js


# run until GitHub rate limit is reached
# or in src/server/util/API.js add a rateLimitExceeded = true around below code
#           default:
#                rateLimitExceeded = true
#                if (message.startsWith('API rate limit exceeded')) {
#                    rateLimitExceeded = true
#               }
#                console.log(chalk.yellow('[WARNING] ' + message))
#            }
# Expected behavior:
# - GitHub rate-limit warning appears
# - "Refresh cycle stopped because the GitHub API rate limit was reached." is logged
# - remaining contributors in that cycle are not processed

@CodeMatrix1
Copy link
Copy Markdown
Author

CodeMatrix1 commented Mar 28, 2026

Hello singli, I realise that the PR with backend changes would have conflicts with this one if merged, I will make sure that conflicts are resolved, Please let me know if the previous PRs needs to be merged to allow new PRs or if I can do anything to help with this slight hitch

@Sing-Li
Copy link
Copy Markdown
Member

Sing-Li commented Mar 30, 2026

we never have had rate limit problem. Thanks for the attempt, though.

@Sing-Li Sing-Li closed this Mar 30, 2026
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.

2 participants