At time to run cron: Trying to access array offset on value of type null in web/core/lib/Drupal/Core/Cron.php

Created on 23 October 2023, 8 months ago
Updated 3 May 2024, about 2 months ago

Problem/Motivation

This is the complete message at time tu run cron.

Warning: Trying to access array offset on value of type null in web/core/lib/Drupal/Core/Cron.php line 264

looks like the code $worker->getPluginDefinition() returns null

Steps to reproduce:

Drupal core:
Drupal version: 10.1.5

Run drupal cron by behat testing:
Behat uses drupal/drupal-extension version v5.0.0alpha1 project to run core/lib/Drupal/Core/Cron.php::processQueue

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Cron 

Last updated 6 days ago

No maintainer
Created by

🇧🇴Bolivia vacho Cochabamba

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

  • Issue created by @vacho
  • Status changed to Postponed: needs info 8 months ago
  • 🇺🇸United States cilefen
  • 🇧🇴Bolivia vacho Cochabamba
  • 🇧🇴Bolivia vacho Cochabamba
  • 🇭🇺Hungary djg_tram

    @vacho -- That's not a solution. This merely silences the error but the worker will never be executed then, given a lease time of nothing.

  • 🇭🇺Hungary djg_tram

    @vacho -- Put a dpm() or similar dump into the first line of that function and check $queue to see which worker actually causes the problem. Then investigate that worker. I had the same problem and it turned out to be an error in the worker's dependency injection (I'm developing it right now, so it was my error in my case). If it's your code, fix it, if it someone else's, contact them for a fix. As it looks, this isn't a Drupal core issue at all -- as soon as I fixed my own code, it went back to normal.

    Basically, the first thing to check is whether line 206:

    $worker = $this->queueManager->createInstance($queue_name);

    can actually instantiate the worker at all. Note that various source sample floating around the web are erronous, if you happen to develop your own worker, be sure to take them with a huge grain of salt.

  • Status changed to Needs review 6 months ago
  • 🇺🇸United States jeffam

    I ran across this error while working on some malformed custom queueworker plugins that worked in Drupal 9 but not in Drupal 10.

    But perhaps the larger issue is that the warning wasn't logged by Drupal. Without any logs, we didn't know about the issue for some time.

    Here's a small patch that logs an error when line 264 in Cron.php fails and sets $lease_time to null.

    This can happen if $worker->getPluginDefinition() fails (as it did in my case) or if the 'time' key is missing from the plugin definition.

  • Status changed to Needs work 6 months ago
  • 🇺🇸United States smustgrave

    Steps should be added to the issue summary, as well as missing sections.

    Changed to 11.x as the current development branch.

    Also as a bug will need a test case.

  • 🇫🇷France zorax Monoblet

    I ran into this problem after updating drupal to 10.2.
    The patch give me "Missing lease time for cron" in my log.
    I created a queue mail function from a sample floating around the web few years ago.
    Can you give me an example, link to a custom queueworker plugins which is well configured for 10.2?

  • last update 6 months ago
    Custom Commands Failed
  • 🇫🇷France zorax Monoblet

    I fixed my problem by reconfiguring the Custom Queue Worker with this example :
    https://www.alansaunders.co.uk/blog/queues-drupal-8-and-9

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    @zorax: What did you actually change about your queue config?

  • @zorax Any information please? I hae the same error after upgrading drupal 9 to 10

  • 🇺🇸United States a-fro

    @liam-morland this was the same issue with the QueueWorkerPlugin we were using.

  • 🇮🇳India nitinkawane

    Patch for Drupal 10.2.5

Production build 0.69.0 2024