BugFix: users can cancel an order cooperatively at the same time#733
BugFix: users can cancel an order cooperatively at the same time#733Matobi98 wants to merge 1 commit intolnp2pBot:mainfrom
Conversation
…nction and update the cancelOrder command to utilize it.
WalkthroughIntroduces a helper function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
bot/commands.ts (1)
734-758:⚠️ Potential issue | 🟠 MajorEmit
orderUpdatedwith the freshly saved order to avoid stale event payloads.
updateOrderis persisted withstatus = 'CANCELED', but the event is emitted with the pre-updateorder, so listeners may seeACTIVEand miss the cancellation. EmitupdateOrderinstead (or re-fetch) to keep downstream state consistent.🛠️ Proposed fix
- logger.info('cancelOrder => OrderEvents.orderUpdated(order);'); - OrderEvents.orderUpdated(order); + logger.info('cancelOrder => OrderEvents.orderUpdated(updateOrder);'); + OrderEvents.orderUpdated(updateOrder);
Description
Fix race condition when processing simultaneous cooperative cancellations: if buyer and seller send
/cancel order-idat nearly the same time both flags (buyer_cooperativecancel,seller_cooperativecancel) were set but the order remained inActivestatus.Now the operation uses an atomic update/lock so when both confirm the order transitions to
cancelledand bot replies remain consistent.Summary by CodeRabbit