[Solved] Losing session after vagrant destroy/up with Symfony


So in the end i solved it by setting session handler to default from php.ini

in config.yml

  session:
    handler_id: ~

there was a race condition because of vagrant shared folders

From: https://github.com/symfony/symfony/issues/7885

The shared vagrant folder has to do a lot of syncing and is much
slower than the rest of the folders on the VM. I think what happens is
Symfony logs the user in, writes a session file then goes to read that
session file and it’s not there yet (because the folder is slow). At
this point Symfony loses the session and the user is effectively
logged back out. Moving the session cache to a faster folder fixes the
issue since the file is there when Symfony expects it. For me it was
actually working on a computer with a SSD (faster IO) and failing on a
computer with a traditional HDD. The SSD was fast enough to be able to
support caching to the shared folder but the HDD couldn’t keep up.
Moving the cache outside of the shared folder fixes it.

solved Losing session after vagrant destroy/up with Symfony