jdavidbakr / MultiServerEvent

Laravel plugin to allow scheduled events across multiple servers with the same scheduler to not overlap.
MIT License
37 stars 17 forks source link

Room for potential race condition #12

Closed benpoulson closed 7 years ago

benpoulson commented 7 years ago

Without row-level locking, or synchronous processing you can't guarantee that two processes won't lock at the same split second.

I would consider ditching the database, and moving over to Redis/Memcached. Or at least looking into Laravel's Pessimistic Locking.

jdavidbakr commented 7 years ago

The way the database entry works should prevent a race condition. The script performs an insert against a table with a unique column for the mutex, if it succeeds then it continues, if it fails it does not. The database will prevent two processes from successfully completing the insert at the same time.