Hey... sometimes when I save changes on the fields settings for a search index I get the following error:

The website encountered an unexpected error. Please try again later.
AssertionError: The container was serialized. in assert() (line 28 of core\lib\Drupal\Core\DependencyInjection\Container.php).
assert(, 'The container was serialized.') (Line: 28)
Drupal\Core\DependencyInjection\Container->__sleep()
serialize(Array) (Line: 157)
Drupal\Core\Batch\BatchStorage->doCreate(Array) (Line: 129)
Drupal\Core\Batch\BatchStorage->create(Array) (Line: 107)
Drupal\Core\ProxyClass\Batch\BatchStorage->create(Array) (Line: 926)
batch_process() (Line: 63)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 591)
Drupal\Core\Form\FormBuilder->processForm('search_api_index_fields', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 694)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

tobiberlin created an issue. See original summary.

drunken monkey’s picture

Status: Active » Postponed (maintainer needs more info)

Seems the container is, indirectly, part of a batch definition there. However, I don’t think the “Fields” form generally triggers any batch operations – unless there are left-over batches from other index operations. So maybe that.
In any case, it’s very hard to say what the actual issue here is, and its cause, without seeing the batch definition in question. Would you be able to get that? (I.e., in \Drupal\Core\DependencyInjection\Container::__sleep(), output the argument of the serialize() call in the backtrace.)

As I don’t think anyone else has reported this problem yet, it’s pretty surely caused by something specific to your setup – possibly even some custom code.
In general, please make sure that you don’t have the container itself in a class property pretty much anywhere, but especially not on classes that might get serialized. (If you do, and there’s no way around it, use \Drupal\Core\DependencyInjection\DependencySerializationTrait.) If you come across such code, then maybe fixing this will already get rid of this problem.

czigor’s picture

Status: Postponed (maintainer needs more info) » Active

This happens to me when clicking the "Execute tasks now" button on the ServerStatusForm. The batch array is getting serialized and it contains a FormState object. My guess is that that's where the container is somewhere.

Looks similar to #2449313: Container and Settings serialize exception when editing server/index..

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new642 bytes

Thanks a lot for the additional information!

The batch array is getting serialized and it contains a FormState object.

Hm, that seems to be normal. And I can’t see how the container might get in there – we don’t really use the form state at all in that form. I guess it has the server in there, as a build arg, but if serializing a server entity were a problem, we’d see that in lots of other places, I’d think.

Any chance you could investigate further? (But I know how tricky that quickly becomes, finding out what exactly gets serialized …)

Also, could you maybe try whether the attached patch helps? (Can you reproduce this reliably?) Probably not, but worth a shot.

Oh, and what server backend plugin are you using?

drunken monkey’s picture

Status: Needs review » Postponed (maintainer needs more info)
czigor’s picture

Sorry for getting back this late. The backend is solr and the issue seems to have originated from importing obsolete config after module updates. Saving the server config form and re-exporting the config fixed it.

drunken monkey’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

OK, thanks a lot for your feedback! Then I’ll just close here.

rlmumford’s picture

Status: Closed (cannot reproduce) » Active

I've run into this same issue when running "Execute tasks now". I have a search index set up using a search_api_opensearch back end. There is no exported configuration involved, this is just the initial setup. The patch listed did not help.

rlmumford’s picture

Status: Active » Closed (cannot reproduce)

Pretty sure this is an error in search_api_opensearch : https://www.drupal.org/project/search_api_opensearch/issues/3262263