Error: Serialization of 'CurlHandle' is not allowed in serialize()

Created on 7 October 2024, 6 months ago

After updating to 8.x-3.0-rc2, we are getting the error "Serialization of 'CurlHandle' is not allowed in serialize()" when the Feeds cron job runs or when deleting existing Feeds items.

It appears to be related to this commit: https://git.drupalcode.org/project/feeds/-/commit/9b60a9bd8ed4186c46250c...

The commit added a reference to loggers in Feeds State which is serialized between batches. Since we use Monolog to send logs to Loggly, the Loggly log handler has a reference to CurlHandle that can't be serialized. As a temporary workaround, we disabled Loggly for the Feeds log channel. But it would be nice to figure out how to serialize Feeds State without the logger object.

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kevin w

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

Merge Requests

Comments & Activities

  • Issue created by @kevin w
  • πŸ‡³πŸ‡±Netherlands megachriz

    I had hoped that DependencySerializationTrait would take care of reinitialising the logger, but I see that the object indeed appears in the serialized text, which I found out using the following code:

    $feed = \Drupal\feeds\Entity\Feed::load(3);
    $state = $feed->getState('fetch');
    $state_serialized = serialize($state);
    var_dump($state_serialized);
    

    To fix this, \Drupal\feeds\State should implement __sleep() to prevent the $logger property from being serialized and implement __wakeup() to restore the logger again.

    It would be cool if we could add a Unit or Kernel test that fails when the logger would get serialized. Probably it would work to mock \Psr\Log\LoggerInterface and let its __sleep() method throw a \LogicException, similar as how \Drupal\Core\Site\Settings does this for example.

  • πŸ‡³πŸ‡±Netherlands megachriz

    Note: since DependencySerializationTrait already implements __sleep() and __wakeup(), these methods should be aliased and then be called from the State::__sleep() and State::__wakeup() respectively.

  • πŸ‡³πŸ‡±Netherlands megachriz

    I think that the code provided in the MR should fix the issue for you.

    @kevin w
    Do you want to test it?

  • πŸ‡³πŸ‡±Netherlands megachriz

    I guess not serializing the logger creates some problems...

  • πŸ‡³πŸ‡±Netherlands megachriz

    The fix was relatively simple, \Drupal\Core\DependencyInjection\DependencySerializationTrait::__sleep() must be compatible with Drupal\feeds\State::__sleep(). So I removed the return value for it.

  • Pipeline finished with Skipped
    5 months ago
    #346103
    • megachriz β†’ committed 644c6d61 on 8.x-3.x
      Issue #3479242 by megachriz: Do not serialize a \Psr\Log\LoggerInterface...
  • πŸ‡³πŸ‡±Netherlands megachriz

    Because there is now an issue related to this one opened whose fix would cause overlap with this one, I merged the code. Feel free to reopen this issue if it didn't completely fix the problem for you.

    The related issue: πŸ› Error: Call to undefined method Drupal\feeds\State::messenger() Active

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

Production build 0.71.5 2024