cron race condition on busy site

Created on 30 August 2015, about 9 years ago
Updated 17 June 2024, 5 months ago

i am running a busy drupal commerce site which creates order on a hook_cron based on recurring entities due dates. i notice that once in a while orders are created twice. the only way this could happen is if cron ran at the same time, and the first cron that executed failed(or delayed) to update the cache. i have cron set to tun every hour.
i looked at the code from cron and it seems like system_run_automated_cron() checks for when cron ran last time, and if it's longer that 1 hour, calls drupal_run_cron().this function eventually gets a lock and calls all implementations of hook_cron() . and finally updates the variable which saves the last time cron ran, and releases the lock.

now, if two visitors of my site happen to hit it at the same time, and the first cron hasn't saved the variable storing the last time drupal ran, it is possible that the second (and even more visitors will pass the condition on system_run_automated_cron() and be put on the queue for the lock on drupal_run_cron()
creating a race condition.

so, i am right, is this possible?
if it is, how can i prevent this behavior?

πŸ’¬ Support request
Status

Fixed

Version

7.0 ⚰️

Component
CronΒ  β†’

Last updated 24 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States gamaliz

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024