voryx / ThruwayBundle

Bundle for building Real-time Apps in Symfony
98 stars 47 forks source link

Kernel is not registered in Worker #45

Open stingus opened 8 years ago

stingus commented 8 years ago

I have a worker which throws the following exception: "You have requested a synthetic service ("kernel")". The DIC does not know how to construct this service.". After some debugging, it seems that the container used in the worker controller does not have the "kernel" service registered. The thruway_client service has the kernel service, but is not available in the controller. The kernel service is required by the file locator service in the appProdProjectContainer.php:

protected function getFileLocatorService()
    {
        return $this->services['file_locator'] = new \Symfony\Component\HttpKernel\Config\FileLocator($this->get('kernel'), ($this->targetDirs[2].'/Resources'));
    }

Any ideas how to avoid this issue?

davidwdan commented 8 years ago

@stingus can you provide the code I need to reproduce the error?

stingus commented 8 years ago

Not my actual setup but it reproduces the error:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Voryx\ThruwayBundle\Annotation\Register;
use Voryx\ThruwayBundle\Annotation\Worker;

/**
 * @Worker("worker", maxProcesses="1")
 */
class Test extends Controller
{
    /**
     * @Register("test")
     */
    public function testAction()
    {
        $this->get('templating')->render('@AppBundle/Mail/body.html.twig');
    }
}

I'm calling the templating service, which loads twig, which loads file_locator service. The last one crashes when it injects the kernel, which is not present in the container.

jonday-simitive commented 7 years ago

Did anything further happen with this issue, we are experiencing the same issue with Symfony 2.8.13 ...

The first call to $this->get('kernel') from inside the ThruwayBundle seems to result in calling the appDevProjectContainer getKernelService which throws the exception but unsure why this would be

Originally thought this might be an issue with Symfony under certain circumstances (It seems like loading the Bundle into a vanilla Symfony install doesn't have the issue).

rsouverain commented 7 years ago

I just had a similar problem

    /**
     * @Register("test")
     */
    public function testAction()
    {
        $firstUser = $this->get('sonata.user.manager.user')->find(1);
        // the process will hang there, not able to do shit
        return ['this is never returned'];
    }

I think this may be related to some errors in yml configs, unrelated with ThruwayBundle, making some services unavailable from a ContainerAwareCommand

jonday-simitive commented 7 years ago

I can't remember the exact details of this because it was so long ago. I can tell you that the issue we had was because we had dependencies on services that injected @session in one of our registered resources. As I understand it you need to move your auth code into AuthProviderClient and use WAMP auth flow. Still not sure if you can get services that depend on session in the auth provider.

lethak commented 7 years ago

Same here, I tried with symfony 2.8.12 and 2.8.28

        "voryx/thruway": "^0.4.2",
        "voryx/thruway-bundle": "dev-master",

as soon as I do from a worker/RPC:

$this->get('templating')->render('@........html.twig'); // Email template

I get

"You have requested a synthetic service ("kernel")". The DIC does not know how to construct this service.

This is quite frustrating

so far I am unable to find the exact cause, I am digging into

vendor/voryx/thruway-bundle/src/Voryx/ThruwayBundle/DependencyInjection/Compiler/AnnotationConfigurationPass.php:56

    if ($class->implementsInterface('Symfony\Component\DependencyInjection\ContainerAwareInterface')) {
        $container->setDefinition($serviceId, $definition)
            ->addMethodCall('setContainer', [new Reference('thruway_container')]);
    } else {
        $container->setDefinition($serviceId, $definition);
    }

Replacing thruway_container with service_container seems to be working, but not sure what is the pupose of having a custom container in the first place