Skip to content

Accessing the kernel after container has been reset throws exception #294

Open
@tdierolf

Description

@tdierolf

Hi,

when one of the items is throwing an error, the standard error handler kicks in and is resetting the container in the child process.

This leads to the kernel not being available in the container any more. As the kernel is a synthetic service and initialises itself during boot(), it's not available any more after a container reset in the error handler.

Any subsequent access to the kernel service throws the following exception:

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]   
The "kernel" service is synthetic, it needs to be set at boot time before it can be used.

Options to reproduce:

  1. Either enable the Symfony Profiler and provoke any error in one of the items to process. Stopwatch is accessing the kernel in console.terminate and thus throws the exception.
  2. Or add some LOC for testing and access the kernel directly, for example directly after the container has been reset in ResetServiceErrorHandler:
    public function handleError(string $item, Throwable $throwable, Logger $logger): int
    {
        $this->resettable->reset();

        try {
            $this->resettable->get('kernel');
        } catch (\Throwable $e) {
            dd($e->getMessage());
        }

        return $this->decoratedErrorHandler->handleError($item, $throwable, $logger);
    }

Output: "The "kernel" service is synthetic, it needs to be set at boot time before it can be used."

Best regards!
Tim

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions