Handle concurrent order taking: User PerOrderIdMutex in takeBuy and takeSell [2/2] - #824
Conversation
|
Warning Review limit reached
More reviews will be available in 22 minutes. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR centralizes per-order concurrency control by introducing ChangesPer-order concurrency control with PerOrderIdMutex
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bot/modules/orders/takeOrder.ts`:
- Around line 144-145: Remove the leftover debug and artificial delay that block
the per-order mutex: delete the console.log('takeSell: Ups...') and the await
new Promise(setTimeout 10000) inside takeSell/runExclusive so the per-order
mutex (orderId) isn't held for 10s; if you need non-blocking diagnostics, log
via the project logger (e.g., logger.debug) outside the critical section or move
any intentional delay outside runExclusive so cancelOrders,
checkHoldInvoiceExpired and invoice subscription aren't stalled.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e7ab9c7c-c9c3-40c3-a805-c6ed34aae816
📒 Files selected for processing (5)
bot/modules/orders/takeOrder.tsjobs/cancel_orders.tsjobs/check_hold_invoice_expired.tsln/subscribe_invoice.tsutil/index.ts
There was a problem hiding this comment.
Reviewed on current head e4dee55. The per-order mutex is now applied consistently in the high-contention paths this PR targets: takebuy, takesell, hold-invoice expiration handling, and hold-invoice settlement/subscription flow. The previously flagged debug delay / console artifact is gone from the current head. I do not see a remaining blocker in the changes that are actually in scope for this PR.
Summary by CodeRabbit
Bug Fixes
Refactor