Problem/Motivation

Redirect 404 decorates logger.factory and switches to it's own Redirect404LogSuppressor class which injects config factory which in turn injects storage which has a database connection.

When testing media_elvis module on a project I noticed that when the form get's rebuild I was getting

LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection

because this project users redirect 404 and we inject the logger.factory there.

Proposed resolution

Not sure if there is a better approach for this, but adding DependencySerializddationTrait to Redirect404LogSuppressor solves the issue.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Primsi created an issue. See original summary.

primsi’s picture

Status: Active » Needs review
StatusFileSize
new887 bytes

Initial patch.

Status: Needs review » Needs work

The last submitted patch, 2: use-2860496-2.patch, failed testing.

primsi’s picture

Status: Needs work » Needs review
StatusFileSize
new885 bytes

Doh, accidental vim delete line dd :|

  • Berdir committed ed12c18 on 8.x-1.x authored by Primsi
    Issue #2860496 by Primsi: Use DependencySerializationTrait in...
berdir’s picture

Status: Needs review » Fixed

Thanks.

gg4’s picture

Status: Fixed » Needs review
StatusFileSize
new621 bytes

I think the latest patch is broken by a typo in the use statement for the trait.

gg4’s picture

Actually, the patch in https://www.drupal.org/node/2860496#comment-11985840 looks ok, but https://www.drupal.org/node/2860496#comment-11985807 is what was committed, which is not so much.

berdir’s picture

Status: Needs review » Fixed

Damn, thanks for catching that. Committed.

  • Berdir committed e5287e3 on 8.x-1.x authored by bonus
    Issue #2860496 by bonus: Use DependencySerializationTrait in...

Status: Fixed » Closed (fixed)

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

cburschka’s picture

This suppressed the error, but introduced a different problem: As the inner objects _serviceId is still set to "logger.factory" (which is overridden), when the object is unserialized it actually gets itself as the inner loggerChannelFactory rather than the overridden core service.

Each time the object is serialized and unserialized, it adds another level to that chain, so you get $this->loggerChannelFactory->loggerChannelFactory->loggerChannelFactory->...

The underlying issue (both for this and for the original problem) is basically a core bug, namely that Drupal's dependency serialization can't handle decorated services: #2896993: Decorated services crash on serialization..

(I don't think this can be easily fixed by a change in this module, though, so it might be simplest to just keep the workaround as it is and hope that the object doesn't get serialized too often. As the decorator doesn't do anything beside suppressing log messages, it is idempotent. The chain should basically keep working until it is too big to cache, so it's not a critical problem.)