[wp-trac] [WordPress Trac] #57924: Cron Goes Missing. _set_cron_array called with incorrect number of crons

WordPress Trac noreply at wordpress.org
Thu Mar 16 16:05:06 UTC 2023


#57924: Cron Goes Missing. _set_cron_array called with incorrect number of crons
--------------------------+------------------------------
 Reporter:  j3gaming      |       Owner:  j3gaming
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Cron API      |     Version:  6.1.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by j3gaming):

 I can confirm my issue is related to #57271
 When ticket #57271 gets fixed. It's highly likely mine will be fixed too.

 I added some logging within update_option. With @domainsupport's help this
 was added:


 {{{
         $wpdb->show_errors();
         $result = $wpdb->update( $wpdb->options, $update_args, array(
 'option_name' => $option ) );
         if ( ! $result ) {
                 if ( 'cron' === $option ) {
                         error_log('Failed to save option "' . $option . '"
 to the wp_options table with value: ' . print_r($value, true) . ' (' .
 gettype($value) . ') and old value: ' . print_r($old_value, true) . ' (' .
 gettype($old_value) . ') and error: ' . $wpdb->last_error);
                         $wpdb->print_error();
                 }
                 return false;
         }
 }}}


 Here is a summary of what the logs say when I have the problem.
 I cut some out since it dumps the entire 22 count array, and is quite
 long. If you want the full log see:
 https://wordpress.org/support/topic/cron-unschedule-event-error-for-
 hook/page/8/#post-16566622


 {{{
 [16-Mar-2023 06:55:01 UTC] wp_schedule_event(1678949732, 'minutely',
 'crontrol_cron_job', array (
   'code' => 'require_once(\'wp-content/cron/email_send.php\');',
   'name' => 'Send Emails',
 ) , .... )

 [16-Mar-2023 06:55:01 UTC] count(get_option(cron)): 22). count(cron): 23

 [16-Mar-2023 06:55:01 UTC] wp_schedule_event(1678949732, 'minutely',
 'crontrol_cron_job', array (
   'code' => 'require_once(\'wp-content/cron/email_send.php\');',
   'name' => 'Send Emails',
 ) , .... )

 [16-Mar-2023 06:55:01 UTC] count(get_option(cron)): 22). count(cron): 23

 [16-Mar-2023 06:55:01 UTC] wp_unschedule_event(1678949672,
 'crontrol_cron_job', array (
   'code' => 'require_once(\'wp-content/cron/email_send.php\');',
   'name' => 'Send Emails',
 ) , .... )

 [16-Mar-2023 06:55:01 UTC] count(get_option(cron)): 23). count(cron): 22
 Failed to save option "cron" to the wp_options table

 [16-Mar-2023 06:55:01 UTC] WordPress database error  for query UPDATE
 `wp_dev_options` SET `option_value` =

 [16-Mar-2023 06:55:01 UTC] Cron reschedule event error for hook:
 crontrol_cron_job, Error code: could_not_set, Error message: The cron
 event list could not be saved.

 [16-Mar-2023 06:55:01 UTC] wp_unschedule_event(1678949672,
 'crontrol_cron_job', array (
   'code' => 'require_once(\'wp-content/cron/email_send.php\');',
   'name' => 'Send Emails',
 ) , .... )

 [16-Mar-2023 06:55:01 UTC] count(get_option(cron)): 22). count(cron): 21

 [16-Mar-2023 06:55:01 UTC] Cron array count is: 21 array ( ... bunch of
 log spam and output of the 21 array values ... )

 [16-Mar-2023 06:55:01 UTC] Cron unschedule event error for hook:
 crontrol_cron_job, Error code: could_not_set, Error message: The cron
 event list could not be saved. true false, Data:
 {"schedule":"minutely","args":{"code":"require_once('wp-
 content\/cron\/email_send.php');","name":"Send Emails"},"interval":"60"}

 [16-Mar-2023 06:55:01 UTC] [1678949702] Started email_send

 [16-Mar-2023 06:55:01 UTC] [1678949702] Started email_send

 [16-Mar-2023 06:55:02 UTC] [1678949702] Ended email_send

 [16-Mar-2023 06:55:02 UTC] [1678949702] Ended email_send
 }}}

 wp_schedule_event runs twice in a row.
 wp_unschedule_event runs, and tries to _set_cron_array
 Database error on wpdb->update failing to save.
 wp_unschedule_event runs again
 Cron runs twice
 One of my crons will be deleted
 Lots of plugins, and core wordpress crons, will have crons be re-added to
 the database. Any custom crons, like those added via WP Control will not
 be re-added.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57924#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list