#1659

fix: hold the 10 issues a day when issues are opened at the same moment

OpenAkiyo974wants to merge intofrom

The problem

ThrottleIssues lets someone open 10 GitHub issues a day through /bug and /feature, on the web and in the app. It checks the count before the request runs, and only counts the issue once GitHub answered 201, so rejected drafts and outages cost nothing. But asking GitHub takes a while, and every request sent in the meantime still finds room left. They all go through, and they all land in this repository's issues.

Reproduced locally: tester had opened 9 issues that day, then 15 requests ran the real middleware at the same instant, each with a step standing in for GitHub that takes 0.8 s:

Issues opened that day, 3 runs
production24, 24, 24
With this fix10, 10, 10

Over HTTP the per-minute limit (throttle:10,1,issues:) cuts a burst down to about 10 requests, so that's still around 19 issues in a day instead of 10, from one account.

The fix

Each issue takes its place in the day's budget before GitHub is asked, and gives it back unless GitHub opened it:

  • The place is taken by incrementing the counter under a short Cache::lock per user. The lock is there because the database cache's increment can lose a count when the first ones arrive together (the same as in #1640). Over the limit, the place is given back and the request gets the usual "Issue limit reached" answer.
  • Anything but a 201 gives the place back: a validation error, a refused draft, a GitHub outage. Only opened issues still count, as before.
  • A budget given back to zero is cleared, timer included, so the 24 hours still start from the first issue GitHub opened rather than from a failed attempt.
  • A request that can't get the lock in time is refused with the same answer instead of a 500, as #1640 does.

Tests

  • keeps the daily limit when the last issue left is opened twice at the same moment: with 9 already opened, the same draft is sent again while GitHub is opening the tenth. The second is refused and the count stays at 10. It fails on production, which opens both.
  • refuses the issue, without asking GitHub, when it cannot get its turn to be counted: the lock times out, GitHub is never called, and the usual 429 answer is returned.
  • The existing tests still pass unchanged: ten a day, failed attempts and rejected drafts not counted, the limit before validation, and the API.
  • pint, rector, phpstan: clean. Full suite with --coverage --exactly=100.0: 6509 passed, 100%. Type coverage: 100%.

Activity

3
coderabbitai[bot]11d ago

WARNING

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06f31f06-43f7-4ee9-84a7-063f8f3f23d6
Commits

Reviewing files that changed from the base of the PR and between 90f528e2143885ab36e93bbb26e755d1f3648d44 and b67113fb454f5b5caee844c6f706c55d16f76ea8.

Files selected for processing: 2

  • app/Http/Middleware/ThrottleIssues.php
  • tests/Feature/Controllers/IssueControllerTest.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

copilot-pull-request-reviewer[bot]reviewed11d ago
copilot-pull-request-reviewer[bot]11d ago

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.