Running 6.13 on Apache 2.2.9, PHP 5.2.6, Windows XP Pro, (here's the killer) 800Mhz Pentium3.
The time limit of 240 secs applied on line 2633 of common.inc is too short for my setup. (cron.php dies with a 500 http response.)
The code a few lines below indicates that cron.php might run for up to an hour without causing concern.
Under *nix, PHP's set_time_limit applies to process CPU time. However the PHP manual (in the notes to set_time_limit) indicates that under Windows "the measured time is real".
I was initially hoping that I could suggest something along the lines of
set_time_limit(get_ini_value(maximum_execution_time) * 10); but get_ini_value() doesn't exist.
Maybe
set_time_limit(running_under_windows ? 3600 : 240);
would do the trick.
As a workaround, I've changed 240 to 900 - it did finish in about 8 minutes elapsed.

Comments

AlexisWilke’s picture

Title: cron.php time limit too short on some systems » cron.php time limit not defined in 6.14?
Version: 6.13 » 6.14

Peter H,

I will assume that you upgraded to 6.14, otherwise you may want to copy and paste what they have done there although I'm changing your issue to the new code which...

Hi Drupal Core guys,

I'm not too sure what that $time_limit variable comes from, but it is not being set anywhere. The result now is that cron.php cannot timeout since passing 0 (or NULL) to set_time_limit() is equivalent to turning off that feature altogether.

I'm just questioning the intend of the variable. Is is expected to be set and did some other code not make it in 6.14?! Just in case I checked the default.settings.php and it is not there (I actually grepped the whole environment and could not find anything defining the variable.)

I think that's a problem since there is a hard limit of 1h for the semaphore!

I would propose something like this just before the call:

  if (function_exists('set_time_limit')) {
    if (!$time_limit || $time_limit > 3500) {
      $time_limit = 3500;
    }
    else if ($time_limit < 240) {
      $time_limit = 240;
    }
    @set_time_limit($time_limit);
  }

Thank you.
Alexis Wilke

Edit: I actually found the "right" issue, I guess... although it looks like a big mess! 8-) #193383: set_time_limit: Centralize calls and prevent warnings and errors

P.S. 2 -- the $time_limit variable was removed and the value of 240 was put back in there (in CVS only for now). So this issue is still valid, although you may want to post in the other issue since that's where they are very much talking about the time limit for CRON.

gpk’s picture

Title: cron.php time limit not defined in 6.14? » cron.php time limit too short on some systems
Version: 6.14 » 6.x-dev

@2, per hass's comment in #193383-129: set_time_limit: Centralize calls and prevent warnings and errors, the umlimited time limit issue was accidentally introduced in 6.14. The fix (reverting the time limit to 240s) will be in 6.15 and is currently available in 6.x-dev.

The 1h semaphore limit thing is shall we say a bit conservative...

Reverting the title of this issue. IMO it's unlikely that the figure of 240 will be increased, however what might be supported is a check to make sure that any higher time limit set in php.ini or .htaccess is not *reduced* to 240s. Then you can configure your own time limit without having to hack core.

AlexisWilke’s picture

gpk,

Agreed. Although if I wanted a longer time for CRON but not anything else, the 240 in Core will have to be changed each time I upgrade. Another way could be to offer a variable that one can set to a value of one's choice with maybe a limit of 30 minutes.

Thank you.
Alexis

ñull’s picture

I agree with AlexisWilke that it should be variable. Cron jobs with search_files module for instance, can take up a very a long time, but we might not want to raise the limit for all other processes in Drupal.

TonyK’s picture

Title: cron.php time limit too short on some systems » Make cron time limit a variable
Version: 6.x-dev » 7.x-dev

The problem still exists in D7.

marcingy’s picture

Category: bug » task

This is not a bug.

marcingy’s picture

Version: 7.x-dev » 8.x-dev

Oh and d8

swentel’s picture

Status: Active » Needs review
StatusFileSize
new486 bytes

Here's a simple patch.

marcingy’s picture

Looks good to me, the bot seems hung however. I'll mark this rtbc once it comes back green.

valthebald’s picture

Status: Needs review » Needs work

If that's a new variable, I suggest it to be configurable via admin/system/config/cron

cyberschorsch’s picture

Status: Needs work » Needs review
StatusFileSize
new3.42 KB

I added the cron time limit as a new config to the system module. The patch is also extending the cron settings form.

Per default, the value is set to 240 as it was hardcoded before.

valthebald’s picture

Status: Needs review » Needs work
StatusFileSize
new4.39 KB

Patch from #11 breaks default values in cron config form:
547998-11.png

cyberschorsch’s picture

Hi valthebad,

does the patch breaks your existing installation or does this error also occures on a fresh install?

marcingy’s picture

There are many settings in core that have no UI. So lets leave the UI as a follow up and get the new functionality into D8.

marcingy’s picture

Status: Needs work » Needs review

#8: 547998-8.patch queued for re-testing.

valthebald’s picture

#16: patch broke existing installation. Fresh install went smoothly

Radon8472’s picture

Status: Needs review » Needs work

The last submitted patch, system_Added-Cron-Time_Limit-547998-11.patch, failed testing.

mpp’s picture

Assigned: Unassigned » mpp
Issue summary: View changes
StatusFileSize
new3.56 KB

Probably better to use a number field over the textfield (https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Nu...), suffix should be field_suffix:

  $form['cron']['cron_time_limit'] = array(
    '#type' => 'number',
    '#title' => t('Time limit'),
    '#description' => t('Set the cron execution time limit in seconds. If set to zero, no time limit is imposed.'),
    '#default_value' => config('system.cron')->get('threshold.time_limit'),
    '#min' => 0,
    '#step' => 1,
    '#field_suffix' => t('seconds'),
  );

This improves UX and there's no more need for a specific validation callback.

The patch needs a re-roll and breaks the patch from https://www.drupal.org/node/2319177:

   // Try to acquire cron lock.
-  if (!lock()->acquire('cron', 240.0)) {
+  if (!lock()->acquire('cron', $time_limit)) {

I suggest to make the lock relative to the cron timeout:

    if (!$this->lock->acquire('cron', $time_limit * 3.75)) {

Since cron settings are no longer in "core" but in the "automated_cron" module (see https://www.drupal.org/node/2507031) the form to edit global cron settings is in CronForm.

mpp’s picture

StatusFileSize
new2.95 KB

Attached a patch that will turn the time limit into a configurable variable.
Left out the form UI because there's a discussion going on about this in https://www.drupal.org/node/2581949.

mpp’s picture

Status: Needs work » Needs review
mpp’s picture

The last submitted patch, 19: 547998-19.patch, failed testing.

mpp’s picture

Assigned: mpp » Unassigned

Status: Needs review » Needs work

The last submitted patch, 20: 547998-20.patch, failed testing.

mpp’s picture

Status: Needs work » Needs review
StatusFileSize
new2.96 KB

Status: Needs review » Needs work

The last submitted patch, 26: 547998-26.patch, failed testing.

mpp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.79 KB

Fixed test.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/core/lib/Drupal/Core/Cron.php
    @@ -111,12 +111,13 @@ public function run() {
    +    $time_limit = \Drupal::config('system.cron')->get('treshold.time_limit');
    

    Please inject the cron configuration

  2. +++ b/core/lib/Drupal/Core/Cron.php
    @@ -111,12 +111,13 @@ public function run() {
    -    if (!$this->lock->acquire('cron', 900.0)) {
    +    if (!$this->lock->acquire('cron', $time_limit * 3.75)) {
    

    That number feels kinda arbitrary, I know its simply 900 / 240 but maybe a quick line of documentation would be nice

  3. +++ b/core/modules/system/config/install/system.cron.yml
    @@ -1,3 +1,4 @@
       requirements_error: 1209600
    +  time_limit: 240
    diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml
    

    Given that we add it, we need to write an hook_update_N() to include the number by default, and then some test for that as well.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

smustgrave’s picture

wanted to bump 1 more time.

cilefen’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.