When using 8.x with the Update module active, the module will always see Drupal as not-up-to-date. Yet no email is ever sent, due to the following exception that gets thrown when the module causes AutomaticCron::onTerminate to be called, and the request time actually starts invoking cron jobs:

      if ($threshold > 0) {
        $cron_next = $this->state->get('system.cron_last', 0) + $threshold;
        if (REQUEST_TIME > $cron_next) {
          $this->cron->run();
        }
      }

While no mail goes out, the following error appears in the watchdog:

      wid: 47
      uid: 1
     type: cron
  message: %type: !message in %function (line %line of %file).
variables: a:6:{s:5:"%type";s:64:"Symfony\Component\DependencyInjection\Exception\RuntimeException";s:8:"!message";s:114:"You have requested a synthetic service ("request"). The DIC does not know how to construct this service.";s:9:"%function";s:43:"service_container_prod->getRequestService()";s:5:"%file";s:171:"/Users/rtoren/projects/drupal8/drupal/sites/default/files/php/service_container/service_container_prod/a1e224f690e8ddf15227b917194424a0d05132adc3cd5f3af47806f418a3aec5.php";s:5:"%line";i:3472;s:14:"severity_level";i:3;}
 severity: 3
     link:
 location:
  referer:
 hostname:
timestamp: 1399691972

The actual "point of death" is in PhpMail::mail():

    // For headers, PHP's API suggests that we use CRLF normally,
    // but some MTAs incorrectly replace LF with CRLF. See #234403.
    $mail_headers = join("\n", $mimeheaders);

    $request = \Drupal::request();

The problem here is the call to \Drupal::request(). I've been able to verify that sometime during the handling of onTerminate, the request object ceases to be available via \Drupal::request() (remember, onTerminate runs only after the browser has received output), if the object is even available. So PhpMail::mail() cannot be called right now this late in the history of the request

Not sure what the fix is, but pretty sure I have the cause down.

Issue fork drupal-2266871

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Priority: Normal » Major

This is at least major!

jhedstrom’s picture

Status: Active » Needs review
FileSize
777 bytes

I've been able to verify that sometime during the handling of onTerminate, the request object ceases to be available via \Drupal::request()

I wonder if re-weighting the AutomaticCron terminate event would resolve this?

Both Drupal\Core\EventSubscriber\KernelDestructionSubscriber and Drupal\system\EventSubscriber\AutomaticCron set a weight of 100. If the destruction subscriber goes first, all services are destroyed:

 /**
   * Invoked by the terminate kernel event.
   *
   * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event
   *   The event object.
   */
  public function onKernelTerminate(PostResponseEvent $event) {
    foreach ($this->services as $id) {
      // Check if the service was initialized during this request, destruction
      // is not necessary if the service was not used.
      if ($this->container->initialized($id)) {
        $service = $this->container->get($id);
        $service->destruct();
      }
    }
  }
jhedstrom’s picture

FileSize
781 bytes

Oops, I had event subscriber priority confused with Drupal weight. The automatic cron should have a higher priority.

Status: Needs review » Needs work

The last submitted patch, 3: automatic-cron-mail-2266871-03.patch, failed testing.

Status: Needs work » Needs review
jhedstrom’s picture

Issue tags: +Quickfix
jhedstrom’s picture

I tried to write tests for this, but the one I expect to fail isn't failing...so perhaps this has been fixed? I can clearly see while stepping through the code that onKernelTerminate does get called before AutomaticCron, but the test doesn't reproduce the behavior here.

mgifford’s picture

Status: Needs review » Needs work

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.

mattshoaf’s picture

Issue tags: +Triaged core major

This patch needs to be rerolled, /core/modules/system/src/EventSubscriber/AutomaticCron.php is now in core/modules/automated_cron

jhedstrom’s picture

So I think the reason that #7's test only patch is passing is that event subscribers with equal priority fire in an indeterminate order. The original error seems to be triggered if the cron subscriber fires after the onKernelTerminate() method. That being said, I have no idea how to provide a test-only patch that would reliably fire to demonstrate that indeterminacy.

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.

luke.stewart made their first commit to this issue’s fork.