Custom Session handler doesn't work

I’m trying to use custom session handler using Google Datastore. There is a part of code of main module:

 public function onBootstrap(MvcEvent $e)
 {
    $sessionConfig = new SessionConfig();

    $sessionManager = new SessionManager($sessionConfig);

    $sessionConfig->setOptions(
        $e->getApplication()->getServiceManager()->get('Config')['datastore-session']['session']
    );

    $sessionsStorage = $e->getApplication()->getServiceManager()->get('CustomSessionStorage\Storage\CustomStorage');
    $sessionManager->setSaveHandler($sessionsStorage->createHandler());

    $sessionManager->start();

    Container::setDefaultManager($sessionManager);
}

But it doesn’t work. Sessions are still using files on server and method “SessionHandlerInterface::open” is never called.

But when I write this code (in the same place onBootstrap), session handler is used and methods “open”, “read” etc is used. Why the first code doesn’t work?

session_write_close();
session_set_save_handler($sessionsStorage->createHandler(), true);
session_save_path('sessions');
session_start();

How to use my custom handler?

I’ve added logging in SessionManager::start https://github.com/zendframework/zend-session/blob/master/src/SessionManager.php#L114
I’ve got the following https://gist.githubusercontent.com/dmitriytestapic/6d8034bdf5ee1cef37359bd1d6bbea70/raw/63787c92581bc352801ae9071c1457c416a200fb/zf2_session.log

Since you’re manually creating your SessionManager instance anyways… have you tried this:

$sessionManager = new SessionManager(
    $sessionConfig,
    null,
    $sessionsStorage->createHandler()
);

My suspicion is that the default PHP save handler is getting initialized somehow during SessionManager construction, so if you can inject the new handler then, it may work.

Unfortunately it didn’t help (