Installation fails if cron runs in parallel

Created on 24 January 2025, 4 days ago

Problem/Motivation

This issue was initially reported in 🐛 Installation fails if cron runs in parallel Active . During the Drupal/Drupal CMS installation, the process fails if an automated cron job is triggered and executed in parallel to the installation. This can occur when certain routes, like CSS/JS asset paths, are accessed during the installation batch process.

Steps to reproduce

  1. Begin the installation of the Drupal Standard profile via the installation interface.
  2. During the installation batch process, manually access any CSS/JS asset route, such as: <YOUR_DOMAIN>/sites/default/files/css/test.css
  3. This access will trigger automated_cron, potentially causing the installation to fail.

Proposed resolution

As the Cron execution was removed during the installation by 📌 Remove the automatic cron run from the installer Needs work , if we introduce a validation step to ensure the cron job is only executed after the installation is fully completed. This can be done by modifying the run() function in Cron.php to include a check for the install_time state variable.

Proposed code snippet:

    // We can only run cron if the installation has been completed.
    if (!$this->state->get('install_time')) {
      $this->logger->warning('Attempting to run cron while the website is not fully installed.');
      return FALSE;
    }

This adjustment will prevent cron jobs from running prematurely during the installation process and help avoid failures.

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

cron system

Created by

🇧🇷Brazil hfernandes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @hfernandes
  • Pipeline finished with Failed
    4 days ago
    Total: 764s
    #404935
  • Pipeline finished with Failed
    4 days ago
    Total: 832s
    #404934
  • 🇬🇧United Kingdom catch

    #833094: Ajax requests in installer cause cron to run prematurely fixed the same issue several years ago. The fix proposed here is very similar.

    There should not be AJAX requests from the installer to the not-yet-installed site, wondering if somehow something in Drupal CMS is triggering this.

  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies .

  • 🇬🇧United Kingdom catch
  • 🇵🇱Poland pjmuszynski

    I'm trying to verify this issue.

  • 🇵🇱Poland piotr pakulski Poland 🇪🇺

    mentoring Piotr on this one

  • 🇵🇱Poland pjmuszynski

    I was able to reproduce this issue, but sadly the fix doesn't work for me :(

    Steps taken:

    The steps to make sure that the issue is not present without the simultaneous cron run

    1. I initialized the Drupal 11 site.
    2. I installed the site via web UI by choosing the Standard installation profile.
    3. The process went without issues.

    The steps with simultaneous cron run (during the install process)

    1. I initialized the Drupal 11 site.
    2. I installed the site via web UI by choosing the Standard installation profile.
    3. At the same time as the batch process continues I run the drush cron from the console.
    4. The installation fails with the error: "The website encountered an unexpected error. Try again later." (more info in the screenshot attached).
  • 🇬🇧United Kingdom catch

    The cron run may be a red herring here - the overall issue is that any request to the site while the installer is running, can result in cache corruption.

  • 🇧🇷Brazil hfernandes

    @catch It’s possible.

    @pjmuszynski Running the cron via the Drush CLI will consistently cause the installation to fail. While this doesn’t seem like a valid scenario—since it's unlikely someone would execute Drush commands during the Drupal installation—any Drush command (e.g., drush st) will also trigger a failure. This happens because Drush bootstraps Drupal to execute commands, which might align with what @catch mentioned earlier.

Production build 0.71.5 2024