Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. WalkthroughChangesHWID registration flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to HWID registration now atomically enforces device limits while retaining existing-device refresh behavior. No current merge-blocking risk is identified. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant RequestA
participant RequestB
participant SubscriptionOperation
participant register_user_hwid
participant Database
RequestA->>SubscriptionOperation: validate HWID
RequestB->>SubscriptionOperation: validate HWID
SubscriptionOperation->>register_user_hwid: register with limit
SubscriptionOperation->>register_user_hwid: register with limit
register_user_hwid->>Database: acquire database lock
Database-->>register_user_hwid: serialize registration
register_user_hwid->>Database: insert or refresh HWID
register_user_hwid-->>SubscriptionOperation: True or False
SubscriptionOperation-->>RequestA: 200 or 403
SubscriptionOperation-->>RequestB: 200 or 403
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Concurrent subscription requests with different HWIDs can both pass the device-count check and consume the same final slot. Move the check into registration and serialize it with a database lock, so only one new device is admitted while repeat requests from an existing device remain allowed.
PostgreSQL/MySQL lock the parent user row; SQLite acquires a write lock before reading the HWID set. End the validation read transaction first so MySQL's default REPEATABLE READ cannot reuse an older snapshot after waiting for the lock.
Type of change
Checklist
Testing
python -m pytest tests/api/test_hwid.py tests/api/test_user.py -k hwid -q --tb=short: 13 passed, 83 deselected on SQLite.last_used_at; rejected registrations release the lock.git diff --checkpassed.Screenshots
Not applicable.
Notes for reviewers
The registration helper still owns its commit and now returns whether the device was accepted. The operation maps rejection to the existing 403 response. Existing HWID policy resolution, unlimited registration, and subscription response behavior are unchanged.
Summary by CodeRabbit