Page MenuHomeIn-Portal Phabricator

INP-1753 - Racing condition during Scheduled Tasks execution
ClosedPublic

Authored by alex on Apr 1 2026, 6:12 AM.

Details

Test Plan

Preparations

  • in IDE:
    1. go to Languages & FrameworksPHPDebug section of the PhpStorm settings dialog
    2. set Max simultaneous connections setting to 3
    3. save changes
  • in Admin Console:
    1. go to ConfigurationWebsiteAdvanced section
    2. enable Use Cron to run Scheduled Tasks setting
    3. save changes
    4. go to ConfigurationWebsiteScheduled Tasks section
    5. disable all scheduled tasks
    6. pick several tasks that are executed each minute (update Run Schedule of any other task to make it usable in the test)
    7. enable picked tasks (Cancel them if they're marked as running currently)
  • in IDE:
    1. replace the body of the above-chosen scheduled tasks with echo #' . getmypid() . ' - ' . $event . PHP_EOL;
    2. place breakpoint on if ( !$this->claim($event_data, $start_time) ) { line in \kScheduledTaskManager::runAll method
  • in Terminal (start 2 windows in parallel):
    1. enable debugging from CLI
    2. run php tools/cron.php in the folder of the project

Test Plan

NOTE: The goal is to test that even if both tools/cron.php started with the same available scheduled task list, they won't execute scheduled tasks processed from the parallel process.
  1. in the 1st process use Step Over in PhpStorm
  2. confirm that claiming succeeded and you're able to execute the $this->run($event_data, $start_time); line
  3. in the 2nd process use Step Over in PhpStorm
  4. confirm that claiming failed and you're redirect to the next scheduled task execution (if any)

Diff Detail

Repository
rINP In-Portal
Branch
branches/5.2.x
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 11214
Build 3914: arc lint + arc unit

Event Timeline

alex created this revision.Apr 1 2026, 6:12 AM
alex requested review of this revision.Apr 1 2026, 6:12 AM
alex edited the test plan for this revision. (Show Details)Apr 1 2026, 6:17 AM
erik requested changes to this revision.Apr 1 2026, 7:59 AM

Perfect logic, but one minor bug is detected.

There is bug, preventing scheduled task for running at all, when LastRunOn is NULL. In this case claim SQL WHERE condition part is incorrect ("LastRunOn = NULL"). Should be "LastRunOn IS NULL" or ISNULL(LastRunOn) in such cases.

This revision now requires changes to proceed.Apr 1 2026, 7:59 AM
alex updated this revision to Diff 1463.Apr 1 2026, 8:32 AM

Handle the case when LastRunOn or NextRunOn could be NULL.

erik accepted this revision.Apr 1 2026, 9:24 AM
This revision is now accepted and ready to land.Apr 1 2026, 9:24 AM
This revision was automatically updated to reflect the committed changes.