Avoid order version mismatch issues in closeOrder

Created on 19 May 2025, 19 days ago

Problem/Motivation

When processing recurring orders, the closeOrder() method may result in an EntityStorageException: The entity was modified while being edited (order version mismatch) under certain conditions. This typically happens when:

  • The order is saved multiple times during the payment flow (e.g., inside createPayment()).
  • The order entity passed into closeOrder() is outdated due to concurrent saves.
  • No explicit loadForUpdate() is used prior to critical operations like payment creation or order state transitions.
  • This race condition can affect recurring payments, especially under concurrency or when using queue-based processing.

Steps to reproduce

There are no clear Steps to reproduce since it's a race condition and doesn't always happen

Proposed resolution

Use loadForUpdate() on the order entity in closeOrder() immediately before initiating payment creation. This ensures:

  • The order entity is locked and up-to-date.
  • Concurrent modifications are blocked during critical logic.
  • Prevents version mismatch errors in production environments with multiple queue workers or cron tasks.

Remaining tasks

  • Add loadForUpdate() before payment creation in closeOrder().
  • Ensure consistency across any other areas that might modify the order during payment handling.
  • Add a test case simulating concurrent modifications or payment gateways that save the order.

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇯🇴Jordan Abdelrahman khlefat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024