Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tdierolf opened this issue Nov 18, 2024 · 3 comments
Open

Comments

@tdierolf
Copy link

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

@theofidry
Copy link
Collaborator

Wouldn't using subscribed services solve the issue though? https://github.com/webmozarts/console-parallelization?tab=readme-ov-file#subscribed-services

@tdierolf
Copy link
Author

I don't know. In my personal case, I am not using the kernel service at all. But the WebProfilerBundle apparently does and is causing this issue. So it's more of an "internal" thing.

@theofidry
Copy link
Collaborator

theofidry commented Nov 27, 2024

Do you have a reproducer?

This sounds a bit weird, we do use this package extensively and did not have that issue so far ever since we used subscribed services. So having a clear way to check what is going on would be very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants