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, about 1 year ago
Updated 3 May 2024, 7 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 25 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 about 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ด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 11 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 11 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 10 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.71.5 2024