WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9318 closed defect (bug) (fixed)

wp_reschedule_event peggs CPU when very old timestamp is passed in as argument

Reported by: natethelen Owned by:
Milestone: 2.8 Priority: normal
Severity: major Version: 2.7
Component: Administration Keywords: has-patch tested
Focuses: Cc:

Description

Somehow a wp-cron timestamp got create/set with a very old timestamp of 1070. I am sure there is a bug elsewhere that caused this but now that it has happened, WordPress does not recover very gracefully. The result is that when wp_reschedule_event is called, the CPU pegs as it tries to increment it by the $interval until eventually it times out. This causes wp-crop to fail from then on. A possible solution is to set it to time() + $interval instead of incrementing. Or only increment if $timestamp < time() - (2 * $interval).

Attachments (1)

9318.diff (639 bytes) - added by Denis-de-Bernardy 5 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 natethelen5 years ago

Here is the change I made which cleaned up the problem. I replaced:

while ( $timestamp < time() + 1 )

$timestamp += $interval;

with:

$now = time();

if($timestamp >= $now)

$timestamp = $now + $interval;

else

$timestamp = $now + ($interval - (($now - $timestamp) % $interval));

This keeps the $timestamp in line with the difference from time() just like incrementing does, but without having to loop

Denis-de-Bernardy5 years ago

comment:2 Denis-de-Bernardy5 years ago

  • Keywords has-patch tested added; wp-cron wp_reschedule_event removed
  • Milestone changed from Unassigned to 2.8

comment:3 ryan5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10969]) Fix handling of old timestamps in wp_reschedule_event(). Props natethelen. fixes #9318

Note: See TracTickets for help on using tickets.