Skip to content

Lazycron Stops Working #1323

Open
Open
@netcarver

Description

@netcarver

In certain conditions on our production server, core's LazyCron module stops working totally and needs to be manually restarted by deletion of the site/assets/cache/LazyCronLock.cache file. This has been reported as far back as 2015 and is an ongoing issue that makes LazyCron too unreliable for serious use.

Expected behavior

LazyCron should be reliable enough to use in production, even if the code it's calling via hooks is not reliable.

Actual behavior

By failing to remove its lockfile when PHP Errors are raised, Lazycron stalls when it sees its lockfile still present and fails to be reliable for running any of its other hooks.

Cause of Issue

Investigation shows that whilst LazyCron is catching \Exceptions thrown from it's hooked calls, it is not handling PHP Errors. If any PHP error occurs in a called hook, Lazycron does not handle it and it bubbles up to the global error handler.

In these cases, LazyCron's lockfile is left on disk and the next call that invoke's Lazycron sees the lockfile and does not execute as it thinks another copy of itself might be running.

Suggestion for a possible fix

Now that PHP7 is common, both exceptions and errors are thrown and are catchable. Perhaps it's time to catch(\Throwable $e) as well as just catching exceptions. Specifically around L187 and L202. Something like the comment here.

Local testing shows that this does allow LazyCron to remove its lockfile when hooks generate errors. This allows subsequent executions of LazyCron to continue, and it should also allows later hooks in its list of hook methods to also be called, rather than being bypassed.

If PHP5 support is needed then a custom error handler should be included in LazyCron that cleans up the lockfile if an Error is raised.

Steps to reproduce the issue

Write a LazyCron hook that does a divide by zero or raises any other PHP error.

Setup/Environment

  • ProcessWire version: 3.0.148
  • PHP version: 5 or 7 - suggested fix only tried on PHP7.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions