ECA Processing Queued Task error

Created on 18 July 2024, 8 months ago

Problem/Motivation

When processing a task from the queue, \Drupal\eca_queue\Task::isDueForProcessing() throws an exception, "Typed property Drupal\eca_queue\Task::$time must not be accessed before initialization". This makes queue processing fail.

Steps to reproduce

Create a model that uses the ECA processing queued task event. Use an "Add to queue" action to add something to the queue. Run cron.

Proposed resolution

This is a regression from Commit 776e9526, for πŸ“Œ PHPStand level 6 fixes Fixed . That commit added dependency injection to inject the time service, instead of calling it using the non-DI \Drupal::time() call.

The problem is, this task object is unserialized from the queue, and so its constructor is not called -- according to the docs for unserialize(), it explicitly skips the constructor.

Remaining tasks

We could implement an __unserialize() method to re-add the time service, but I'm thinking it's easier/cleaner to just revert to using \Drupal::time() -- I'm not aware of a standard way to do dependency injection on unserialized objects, so I would tend to go with the simpler solution rather than adding complexity here.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

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

Merge Requests

Comments & Activities

  • Issue created by @freelock
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    MR created.

  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Note that this was introduced in the 2.x branch, does not affect 1.x.

  • Pipeline finished with Failed
    8 months ago
    Total: 535s
    #228083
  • Status changed to Active 7 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I can't reproduce this issue. And I can't even find any documentation that would explain that the constructor is not called for unserialized objects. Can you please provide more details on how this can be reproduced?

    In any event, using \Drupal::something would always create CI pipeline errors. We have to avoid that if we want clean code. So, if this is really an issue, there must be another way of resolving it.

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    See https://www.php.net/manual/en/function.unserialize.php - after recreating the object, the __wakeup or __unserialize method on the object is called, if one exists.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Yes, I saw that too, but that doesn't say that __construct isn't executed.

    Still, I can't reproduce the problem. I've created a model that adds a job to the queue. And it also contains a cron event for that job that prints a message. All that works without any error message. What can we do here? I'm really uncertain.

  • πŸ‡©πŸ‡ͺGermany mxh Offenburg

    The

    __construct

    method never gets called when an object is being unserialized. The magic method __wakeup will be called for this particular case. Since it's about a missing service, using DependencySerializationTrait β†’ within Drupal\eca_queue\Task may be the solution path.

  • Status changed to Needs review 7 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Ah, good one. Thanks @mxh for the hint. I've committed that to the dev branch 2.1.x, @freelock could you give that a try if this also works in your context?

  • πŸ‡©πŸ‡ͺGermany mxh Offenburg

    I don't see the commit at the moment, am I missing something?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    My bad, I've been in an issue fork when I committed that yesterday. Fixed now, it's ready for testing in the dev release.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    jurgenhaas β†’ changed the visibility of the branch 3462442-eca-processing-queued to hidden.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    I still can't reproduce this on most Drupal sites, but we now had a customer site which suffered from the same issue. By applying the fix from #11 the error has gone away.

  • Status changed to RTBC 7 months ago
  • Status changed to Fixed 7 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Back ported to 2.0.x

  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    I can confirm that I have the same issue.
    In my case it was decoupled Drupal site and 2 ECA was triggered:
    - Entity insert
    - Entity update
    - And related queue process

    Updating to 2.0.1 fixed an issue.
    It was hard to find it on the site and even debug it, in my case it ended with the error:
    Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed.

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

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Ok this just bit me again... the fix does not fix my installation, at least not under PHP 8.1. The DependencySerializationTrait does not appear to be adding the Time service to the _serviceIds[] property of the serialized object, so it does not add it back to the rehydrated Task object.

    This has led to thousands of unprocessed queue items...

    Can we re-open this issue? The original MR did fix it on my installation -- reapplying that as a patch is fixing it for me. DependencySerializationTrait did not fix it. A simple __unserialize() or __wakeup() method that adds this back might also work -- although it loses any benefit of dependency injection (if a different class was injected in the first place).

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    @freelock this is really strange since it is working in so many places just fine. Instead of re-opening this issue, please open a new one and provide a model with which this can be reproduced. Then we can see, where this goes wrong and fix it the right way.

  • Pipeline finished with Skipped
    about 2 months ago
    #393144
  • Pipeline finished with Success
    about 2 months ago
    Total: 30572s
    #392930
  • Pipeline finished with Failed
    about 2 months ago
    Total: 906s
    #396829
  • Pipeline finished with Failed
    28 days ago
    Total: 890s
    #412808
  • Pipeline finished with Success
    27 days ago
    Total: 279s
    #414378
  • Pipeline finished with Failed
    13 days ago
    Total: 1181s
    #427570
Production build 0.71.5 2024