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.

Issue fork feeds-3479242

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:

Comments

kevin w created an issue. See original summary.

megachriz’s picture

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.

megachriz’s picture

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.

megachriz’s picture

Status: Active » Needs review
Issue tags: -Error: Serialization of 'CurlHandle' is not allowed in serialize()

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

@kevin w
Do you want to test it?

megachriz’s picture

Status: Needs review » Needs work

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

megachriz’s picture

Status: Needs work » Needs review

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.

  • megachriz committed 644c6d61 on 8.x-3.x
    Issue #3479242 by megachriz: Do not serialize a \Psr\Log\LoggerInterface...
megachriz’s picture

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: #3487439: Error: Call to undefined method Drupal\feeds\State::messenger()

Status: Fixed » Closed (fixed)

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