title: Symfony: Warning: session_start(): Failed to decode session object. Session has been destroyed
body: <p>Symfony gives me an error when I try to switch users (impersonate) using <code>_switch_user</code>. It started happening probably after changing sessions table name. Everything else works fine (setting and getting data from session without impersonating).</p>
  
  <blockquote>
    <p>Warning: session_start(): Failed to decode session object. Session has been destroyed</p>
  </blockquote>
  
  <p>Precise error from logs</p>
  
  <blockquote>
    <p>[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)"} []</p>
  </blockquote>
  
  <p>Precise line which triggers an error (<code>\src\EventListener\MyListener.php</code>)</p>
  
  <pre><code>public function onKernelRequest(RequestEvent $event) {
     $request = $event-&gt;getRequest();
     $request-&gt;getSession()-&gt;set('hash', $_ENV['HASH']);
  }
  </code></pre>
  
  <p>My session handler config (<code>config\services.yml</code>)</p>
  
  <pre><code>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 }
  </code></pre>
  
  <p>My session config (<code>config\packages\framework.yml</code>)</p>
  
  <pre><code>session:
          handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
          cookie_samesite: 'none'
          cookie_secure: true
          cookie_httponly: true
          gc_probability: 0
  </code></pre>
  
  <p>I am using</p>
  
  <ul>
  <li>Symfony 4.4.2</li>
  <li>PHP 7.2</li>
  <li>"friendsofsymfony/user-bundle": "2.1.2"</li>
  </ul>