Description
Symfony version(s) affected: 5.x
Description
I was testing one of our main apps in 5.x and discovered a regression with the new session logic when using the token storage, causing "There is currently no session available." (related change: #38616)
We use a listener on kernel.terminate
to log some information (including the current username). However, RequestStack::getSession()
only works when there is a main request (which is not the case in the kernel.terminate
event). Before 5.3, the session
service was usable outside a main request.
The fix on our side was quite easy: use the security.untracked_token_storage
service. Yet, I do believe there should be no hard breaks
How to reproduce
- Create a listener on
kernel.terminate
- Try to use the session
Possible Solution
Maybe store the main $request->getSession()
(in RequestStack::push()
) in a variable and use it when there is no main request anymore? (and immediately deprecate this behavior) This way, there is no hard break between the version upgrade and there is a way to direct the user into the right debugging path.