-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Fix TypeError on null $_SESSION
in NativeSessionStorage::save()
#46808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Build failures unrelated. |
Thanks. This will definitely fix the issue for me but I am not sure why $_SESSION is null and I can't reproduce it. I only see the error stacktrace in newrelic. I think it was always potentially null sometimes prior to PHP 8.x too and array_keys() just changed to no longer accept null. I am going to keep trying to reproduce it in my app. |
I finally figured out how to reproduce this. If you delete the session cookie This error is different in my development environment but in production $_SESSION would be null and would error when it gets passed to array_keys() on line 246 in NativeSessionStorage.php. The session does get successfully recreated from the remember me cookie, but $_SESSION is still null on that first request in the controller and when you send a 2nd request everything works correctly. |
Just for some added context. This was happening before in PHP 7.4 too, but it only started throwing an exception in PHP 8. In PHP 7.4 it was only a warning hence why I didn't see this error show up in production NewRelic.
|
Now that I understand the problem a little more, I am not sure if the above patch is the right fix. When you use remember me cookie and session cookie expires, remember me cookie should recreate the session which it does, but it seems like it happens at the end of the request lifecycle so anything that calls SessionInterface::save() before $_SESSION is recreated will fail. Should something be reinstantiating $_SESSION earlier in the request lifecycle? As a temporary workaround in my app, I am testing this. It does fix the issue but I am not sure yet if this will have any negative side effects:
|
@jwage Unless I'm mistaken the issue is only with |
@chalasr that makes sense then. Thanks! |
Thank you @chalasr. |
When sending concurrent requests via ajax async to a route pointing to a controller requiring an authenticated user through a stateful - session-based - firewall that calls
SessionInterface::save()
, it happens that$_SESSION
isnull
under some conditions which causes the following error on PHP 8.1:The issue prevents me from upgrading to PHP 8.1 in a project I'm working on with @jwage.