Conversation
…ryError wrapping Replace JS-side .sort() with .orderBy(asc(wallets.id)) in the FOR UPDATE query so PostgreSQL itself enforces consistent lock acquisition order, eliminating the circular wait that causes deadlocks. Unwrap DrizzleQueryError when catching postgres errors — Drizzle wraps raw PostgresError in a generic Error with cause, so check both the error and error.cause for the pg error code. Add PG_DEADLOCK (40P01) as a handled code with a ConflictException response as a safety net. Add unit test for the DrizzleQueryError wrapping path, concurrency e2e spec, and set runInBand: true in jest-e2e.json to serialize e2e runs.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly hardens the purchase system by addressing potential concurrency issues and centralizing UUID validation logic. The changes ensure that concurrent purchase requests are handled reliably, preventing deadlocks and correctly managing idempotency keys. By extracting the UUID regex, the PR also improves code maintainability and consistency for UUID validation across different modules. The addition of new E2E tests provides strong assurance of the system's stability under high load. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly hardens the purchase logic by improving concurrency handling and centralizing validation. The introduction of orderBy in the SELECT FOR UPDATE query is the correct approach to prevent deadlocks, and the enhanced error handling for wrapped Postgres errors makes the service more robust. The new end-to-end concurrency tests are a great addition, providing confidence in these critical paths. I have one minor suggestion to refactor the error handling block to improve its structure.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis change refactors UUID validation by extracting a shared 🚥 Pre-merge checks | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/concurrency.e2e-spec.ts`:
- Around line 42-61: The fixture seeding silently no-ops because
.onConflictDoNothing() on schema.wallets can skip inserting required wallet
rows; change the wallets insert to either remove .onConflictDoNothing() or
replace it with an upsert such as .onConflictDoUpdate(...) that sets the desired
fields (e.g., balance and userId) so the fixture always exists with expected
values, and add a quick assertion/guard after the transaction (or inside it) to
throw if the wallets table did not contain the expected rows (e.g., check
affected row count or select the inserted IDs) so the test fails fast instead of
proceeding with missing fixtures; update references in this block
(db.transaction, tx.insert(schema.wallets),
PLATFORM_WALLET_ID/ALICE_WALLET_ID/BOB_WALLET_ID) accordingly.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
src/common/guards/user-id.guard.tssrc/common/validation/uuid.tssrc/purchases/dto/purchase.dto.tssrc/purchases/purchases.controller.tssrc/purchases/purchases.service.spec.tssrc/purchases/purchases.service.tstest/concurrency.e2e-spec.tstest/jest-e2e.json
|
@coderabbitai review |
|
It looks like you're trying to request a full code review. To initiate a new code review, please use the command |
|
✅ Actions performedReview triggered.
|
071aefe to
7596353
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/concurrency.e2e-spec.ts`:
- Around line 43-55: The platform fixture inserts in the db.transaction using
tx.insert into schema.users and schema.wallets are not idempotent and cause
duplicate key errors; modify the seeding so it is safe to run multiple times by
using an upsert/ignore-on-conflict strategy (e.g., insert with ON CONFLICT DO
NOTHING or equivalent upsert method provided by your DB library) when calling
tx.insert for schema.users and schema.wallets, or check existence before
inserting, ensuring PLATFORM_ID/PLATFORM_WALLET_ID rows are skipped or merged
rather than re-inserted.
e6d0a8b to
0738bf3
Compare
|
@coderabbitai review |
|
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Code Review
This pull request significantly hardens the purchasing functionality by improving deadlock prevention, making error handling more robust, and adding comprehensive end-to-end concurrency tests. The refactoring of UUID validation into a shared constant is also a good improvement for maintainability. My review includes one suggestion to further align with NestJS conventions by using a validation pipe in the controller.
No description provided.