Redis sessions null using Symfony 3.4 in our build pipeline

We’re testing migrating an app from Silex to Symfony 3.4 using the Microkerneltrait for a micro app with Symfony. This is all working locally in our dockerised environment but we’re seeing some different behaviour in our build pipeline in Jenkins.

We’re using Redis for Sessions and i’ve added the SNC Redis Bundle for doing this in Symfony. We’re pushing the same config to the build which we use locally. We’re also using the same docker images remotely we’re using in local dev. However, in our build the first instance where Sessions are required we get an error:

PHP Fatal error: Uncaught
SymfonyComponentDebugExceptionFatalThrowableError: Call to a
member function start() on null

This references the session being retrieved from the Request object and started in an Event Subscriber:


    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $session = $request->getSession();
        $session->start();
        // etc...
    }

I can recreate this error locally by using an incorrect dsn for Redis but i’m almost certain the setup is correct for the build as we’re using a very standard Redis image on the standard port, so our dsn in both instances is redis://redis:6379. Other parts of our app which also use Redis are also working correctly so Redis is definitely up and working.

The relevant config.yml is this:

framework:
  secret: 'S0ME_SECRET'
  session:
    handler_id: snc_redis.session.handler

snc_redis:
  clients:
    session_client:
      dsn: 'redis://redis:6379'
      logging: '%kernel.debug%'
      type: phpredis
  session:
    client: session_client
    prefix: "PHPREDIS_SESSION:"

In debugging, one thing I spotted is that in my local setup, running the app changes the session.save_handler to "user" but this doesn’t appear to happen in our build (it remains as "files"). Does this imply that somehow the bundle isn’t being registered correctly?

Source: Docker Questions