As David Rothstein already realized in #805702-20: Cron should use locking framework:

As far as I understand, set_time_limit() only affects the actual PHP code execution time, which is not the same as the elapsed 'wall clock' time, which can be substantially different due to database queries, etc (see the note at http://php.net/manual/en/function.set-time-limit.php). So there is no particular reason why the lock should be held for only as long as the maximum script execution time.

Exactly. I've seen many concurrent cron runs piling up on a server, because of the search api server becoming unavailable. Search API tries to index during cron run and its connections waiting for response are not covered by the php time limit.

Reverting the lock time limit to a safe value of 3600s as it was before #805702: Cron should use locking framework seems to be reasonable and avoids multiple, concurrent cron runs.

Patches for d8 and d7 attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
516 bytes

rerolled, no reason to hold this up.

alexpott’s picture

1 hour seems like a super long time - up from 4 minutes.

catch’s picture

Status: Reviewed & tested by the community » Needs work

This was discussed in #805702: Cron should use locking framework a bit, looks like we changed to 240s on purpose but I'd suggested 15 minutes before that - what about 15 minutes then? Agreed an hour seems much too long - that's enough for things to get backed up on a busy site.

swentel’s picture

Status: Needs work » Needs review
FileSize
515 bytes

Hmm right, I was somehow misreading this completely to 300 (which then would only be one minute more) - new patch to 15 minutes.

catch’s picture

Also not necessarily in this issue, but what about renewing the lock after each cron handler and before running queues?

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Sounds like we have an agreement on 15min then?

Doing it per hook/queue runner sounds interesting but yes, separate issue.

  • catch committed 735f55e on 8.0.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...
catch’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Opened #2340043: Re-aquire lock during cron runs.

Committed/pushed to 8.0.x, thanks!

  • catch committed 735f55e on 8.1.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...

  • catch committed 735f55e on 8.3.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...

  • catch committed 735f55e on 8.3.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...

  • catch committed 735f55e on 8.4.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...

  • catch committed 735f55e on 8.4.x
    Issue #2319177 by swentel, fago: Fixed Cron lock time limit is too short...
poker10’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and it still applies to D7. Code is the same as in D9. Setting this as RTBC.

The last submitted patch, d7_cron_lock-do-not-test.patch, failed testing. View results

poker10’s picture

Status: Reviewed & tested by the community » Needs review

But considering the state of D7, don't we want to make it configurable via settings.php? If we want as many sites as possible to benefit from this fix then the opt-out variant should be better in my opinion (who wants to keep the current lock time limit would be able to do so).

Not creating a new issue yet in case we will commit #9, but if not, I will create a D7 backport follow-up issue.

mcdruid’s picture

Yes, I think we should make this configurable in settings.php but would be happy to change the default to 15 mins to align with D9.

poker10’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs review » Fixed

I am closing this as Fixed in D8 and created a follow-up for D7, so we can finish the new approach there.

#3308929: [D7] Cron lock time limit is too short and does not prevent multiple, concurrent cron runs

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.