Symfony gives me an error when I try to switch users (impersonate) using _switch_user
. It started happening probably after changing sessions table name. Everything else works fine (setting and getting data from session without impersonating).
Warning: session_start(): Failed to decode session object. Session has been destroyed
Precise error from logs
[2020-05-21 11:28:37] php.WARNING: Warning: session_start(): Failed to decode session object. Session has been destroyed {"exception":"[object] (ErrorException(code: 0): Warning: session_start(): Failed to decode session object. Session has been destroyed at /app/my_app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:151)"} []
Precise line which triggers an error (\src\EventListener\MyListener.php
)
public function onKernelRequest(RequestEvent $event) {
$request = $event->getRequest();
$request->getSession()->set('hash', $_ENV['HASH']);
}
My session handler config (config\services.yml
)
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
public: false
arguments:
- 'mysql:host=%env(DATABASE_HOST)%;dbname=%env(DATABASE_NAME)%'
- { db_table: 'my_sessions', db_username: '%env(DATABASE_USER)%', db_password: '%env(DATABASE_PASSWORD)%', lock_mode: 0 }
My session config (config\packages\framework.yml
)
session:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
cookie_samesite: 'none'
cookie_secure: true
cookie_httponly: true
gc_probability: 0
I am using
- Symfony 4.4.2
- PHP 7.2
- "friendsofsymfony/user-bundle": "2.1.2"