Preventing Race Conditions in SmartForms with LISE

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
WDJames
Forum Members
Forum Members
Posts: 83
Joined: Tue Feb 13, 2018 1:09 pm

Preventing Race Conditions in SmartForms with LISE

Post by WDJames »

Hello,

I have a booking form (using SmartForms) that, on submission, checks if an event (LISE item) has any spaces available. It does this by reading the value of the "spaces" field (UDT).

If spaces are available, the form updates the event's spaces, saves the booking (in another LISE instance), and completes the rest of the dispositions.

The issue I'm running into is race conditions - multiple submissions can overlap and allow overbooking.

Is there a way in my UDT to access a LISE item's "spaces" field and lock it while performing the check?

Thanks

James
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1976
Joined: Mon Jan 29, 2007 4:47 pm

Re: Preventing Race Conditions in SmartForms with LISE

Post by Jo Morg »

Hi James

at this point there is no locking mechanism in LISE and the one in the works is for the editor, at least for now. But you raise a good point, and I'll look into this for a future release.

A possible solution would require some very smart PHP coding in the UDT, either by using a tmp file with a name that could be meaningful and unique that would be locked immediately on submission and only unlocked at the end of the process whether the booking succeeded or not. I don't know how your system works in detail, but that may work, although I can see some issues with the solution. There can be a few different flavors of this but this would be the gist. Using a db lock would also work but you'd need a bit more complex programing.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
WDJames
Forum Members
Forum Members
Posts: 83
Joined: Tue Feb 13, 2018 1:09 pm

Re: Preventing Race Conditions in SmartForms with LISE

Post by WDJames »

Hi Jo,

Thanks for getting back to me. I'm not quite sure how to implement your suggestion.

Just for context, the system works as follows:

1. Booking Form (SmartForms) is submitted.
2. Event's Spaces Available (LISEEvents item) is checked by UDT (triggered by the SmartForm's handler).
3. If there are spaces available, the event's Spaces Available is updated to reduce the Spaces Required by the user and adds/moves the number into the Spaces Pending field. If there are no spaces (or not enough), it returns an error to the user and the process is terminated.
4. After the Spaces Available and Spaces Pending are updated, a Booking Item is created in a different LISE instance (LISEBookings). If required, a Stripe PaymentIntent is created and included with the Booking Item.
5. The user is redirected to a Payment Form (SmartForms).
6. Using the Booking Item's ID, the booking's data is loaded (via UDT) and passed to the Payment Form.
7. User completes the Payment Form.
8. If the booking is free, the Booking Item (LISEBookings) is updated as complete. If the booking is paid, Stripe triggers a webhook that updates the Booking Item. Also the Event's Pending Spaces is cleaned.
9. The rest of the Payment Form dispositions are triggered.

I hope this helps.

Thanks,

James
Post Reply

Return to “Modules/Add-Ons”