The problem
CreateOrgMemberRequest checks who's already in the org and that the org stays within its 256 people. Then CreateOrgMembers inserts the participants without looking again. Two maintainers adding people at the same moment both pass the check:
- Different people, one place left: both are added, and the org ends up over its cap.
- The same person: the second insert hits the
conversation_participants (conversation_id, user_id)unique index. That maintainer gets a 500, and their whole batch is rolled back.
Reproduced locally with two PHP processes, one per maintainer, each running the request's check and then the action at the same instant, on an org with 255 of its 256 places taken:
| Two different newcomers | The same newcomer twice | |
|---|---|---|
production (3 runs) | 257 members, 257, 257 | UniqueConstraintViolationException in one of the two, every run |
| With this fix (3 runs) | 256: one added, the other refused | Both succeed, added once |
The fix
CreateOrgMembers locks the org's conversation row first, the same row messages, reactions and pins lock, then reads who's in again:
- Someone who joined in the meantime is skipped, so adding a person twice is a no-op, not a 500.
- If the batch no longer fits, nothing is added and it throws
OrgIsFull. The web and API controllers answer it with the same 422 the request gives,members: An org holds up to 256 people.
Tests
The tests use beforeResolving(CreateOrgMembers::class) to add a participant after the request's check, as the other maintainer's request would:
adds someone once when two maintainers add them at the same moment(web): 204, and the person is in the org once.keeps the cap when two maintainers fill the last place at the same moment(web), and the same through the API: 422 with the usual message, and the org stays at 256.
All three fail on production (a 500, and 204 instead of 422). The parallel runs above match.
pint, rector, phpstan: clean. Full suite with --coverage --exactly=100.0: 6510 passed, 100%. Type coverage: 100%.
Activity
31a38209WARNING
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 45 minutes.
View limit details
Limit details: You’ve used all 4 included reviews currently available.
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:
ebb1f634-01ab-4986-9aa9-92378ee9f676
Commits
Reviewing files that changed from the base of the PR and between 90f528e2143885ab36e93bbb26e755d1f3648d44 and 1a382093f82dc9aaa9d8ec249faf8e00d73eb179.
Files selected for processing: 6
app/Actions/CreateOrgMembers.phpapp/Exceptions/OrgIsFull.phpapp/Http/Controllers/Api/OrgMemberController.phpapp/Http/Controllers/OrgMemberController.phptests/Feature/Controllers/Api/OrgMemberControllerTest.phptests/Feature/Controllers/OrgMemberControllerTest.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
-
- (https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- Mastodon
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.