Hi Guys

I was testing D8 and got an error when enabling language modules, but seems to me it is a dblog bug.

  1. Install D8 standard
  2. Disabled Overlay
  3. Enable all 3 multilingual (Language, Interface Translation, Content Translation

You should get the error

Error message
Exception: Serialization of 'Closure' is not allowed in serialize() (line 153 of /X/drupal-8.x-dev/core/modules/dblog/dblog.module).
The website has encountered an error. Please try again later.

Cheers

Comments

dawehner’s picture

Component: language system » dblog.module

As errors could put any kind of value into the message it seems to be required to check and filter
out the variables by serializable content. http://stackoverflow.com/questions/5775094/test-if-a-variable-is-seriali... lists some ways to do it, though all feels kind of ugly.

das-peter’s picture

StatusFileSize
new28.4 KB

Just struggled over this while working on #1818556: Convert nodes to the new Entity Field API.
One of the errors is buried in LegacyControllerSubscriber::onKernelControllerLegacy():

    // This BC logic applies only to functions. Otherwise, skip it.
    if (is_string($controller) && function_exists($controller)) {
      $new_controller = function() use ($router_item) {
        return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
      };
      $event->setController($new_controller);
    }

This leads to following trace in the case of an error:

I'm not sure how to proceed, if we've a chance to catch all closures it would be nice to give serializable closures a try.
But it's likely we need a defensive serializing function to deal with all possible cases, even if we build serialzable closures, in sensitive locations. Maybe something like this:

function drupal_serialize($var) {
  try {
      return serialize($var);
  } 
  catch(Exception $e) {
    $arr = array($value);
    array_walk_recursive($arr, new serializable_closure(function (&$element) {
      if (is_object($element) && get_class($element) == 'Closure') {
        $serializable_closure = new SerializableClosure($element);
        $element = $serializable_closure->serialize();
      }
    }));
    return serialize($arr[0]);
  }
}
das-peter’s picture

Status: Active » Needs review
StatusFileSize
new5.73 KB

Here's a first patch.

Status: Needs review » Needs work

The last submitted patch, core-serializable-closure-1872690-4.patch, failed testing.

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new5.7 KB

Oh, that assertion had a Windows specific file path in it. Now it's generic.

Crell’s picture

Can someone perhaps explain to me WHY we need to serialize a closure? What exactly is the use case? The legacy url matcher's closure is not a use case, since I cannot imagine why anyone would be serializing that. It's also intended to be removed once everything is ported to the new routing system.

dawehner’s picture

Well it's not that we need to support it, though when you throw an exception/error and somewhere in the stack is a db connection,
you can't log the error at the moment. This hasn't been a problem in D7, because you never actually stored the db connection somewhere.

Crell’s picture

Storing the DB connection? Wha? Now I'm even more confused.

dawehner’s picture

With "storing" i wanted to express: Something which has the db connection injected.

das-peter’s picture

Can someone perhaps explain to me WHY we need to serialize a closure?

The reason for me to create this was that the "Node creation" test has a test case in which an exception is thrown. The test checks then if the watchdog contains the expected exception.
Unfortunately (on Windows / or even just within my installation) there's a closure in the backtrace of the exception. And this closure kills the whole exception handling because the backtrace can't be serialized.
Now instead to fix "just" the backtrace handling I decided to go for a more "general" solution.

Crell’s picture

peter: Try looking at Symfony's FlattenException class. It's a bit odd, but I think it's also addressing a similar issue in a less language-hostile way. :-)

Or, really, why are we serializing an entire backtrace...?

There's so much here that doesn't make sense to me.

berdir’s picture

The real problem here is #1158322: Add backtrace to all errors IMHO, that's the reason this happens in the first place.

While it makes sense to prevent it for other cases, fixing the other issue is IMHO more important so that we never try to serialize a whole backtrace in the first place.

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, core-serializable-closure-1872690-6.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dagmar’s picture