[wp-trac] [WordPress Trac] #57271: Cron unschedule / reschedule event errors
WordPress Trac
noreply at wordpress.org
Thu May 2 15:03:53 UTC 2024
#57271: Cron unschedule / reschedule event errors
------------------------------------------+------------------------------
Reporter: domainsupport | Owner: audrasjb
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: Cron API | Version: 6.0
Severity: normal | Resolution:
Keywords: needs-unit-tests needs-patch | Focuses:
------------------------------------------+------------------------------
Comment (by j3gaming):
Replying to [comment:76 emilycestmoi]:
> I cannot reproduce "WP cron firing twice in the same microsecond". Can
we get some instructions on how to log this behaviour?
>
> For example, I just modified my wp-cron.php and inserted a line to log
the transient:
>
> {{{
> // XXX-EN
> error_log('got transient: ' . $doing_cron_transient . "\n", 0);
>
> /*
> * The cron lock (a unix timestamp set when the cron was spawned),
> * must match $doing_wp_cron (the "key").
> */
> if ( $doing_cron_transient !== $doing_wp_cron ) {
> return;
> }
>
> }}}
>
> After running this overnight on one of my sites this is my cron log
output:
>
> {{{
> got transient: 1714659602.8254570960998535156250
>
> got transient: 1714659722.2510559558868408203125
>
> got transient: 1714659842.5517539978027343750000
>
> Cron reschedule event error for hook: newsletter_bounce_run, Error code:
could_not_set, Error message: The cron event list could not be saved.,
Data: {"schedule":"newsletter","args":[],"interval":300}
> got transient: 1714659962.9193520545959472656250
>
> got transient: 1714660082.4408359527587890625000
>
> Cron reschedule event error for hook:
cartflows_ca_update_order_status_action, Error code: could_not_set, Error
message: The cron event list could not be saved., Data:
{"schedule":"every_fifteen_minutes","args":[],"interval":1200}
> got transient: 1714660203.2717330455780029296875
>
> got transient: 1714660322.7761120796203613281250
>
> got transient: 1714660442.4618968963623046875000
> }}}
>
> What am I missing?
This is exactly what I'm seeing. In your case, your cron attempted to fire
3 times it looks like. (Never had that happen myself, way to show off) All
with a slightly different microsecond, which allows it to pass the check
intended to stop multiple fires.
If you had set any custom crons with a plugin/custom code, you would find
that they are now gone. The only reason the default cron schedule is not
completely wiped, is because wordpress re-creates the list when
wp_schedule_event is called.
In our case, this could actually easily be fixed changing this line:
{{{if ( $doing_cron_transient !== $doing_wp_cron ) {}}}
to check for a range of time, and not an exact match. One line fix and our
cases would be solved.
As @domainsupport has pointed out, this error has revealed more than 1
problem. You just happen to have the same one as me.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57271#comment:77>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list