-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Use proper error message when session write fails #20807 #21421
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
/** | ||
* @return \SessionHandlerInterface | ||
*/ | ||
public function getHandler(): \SessionHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type is a no-go as Symfony supports PHP 5.x
session_write_close(); | ||
try { | ||
session_write_close(); | ||
} catch (\ErrorException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work in prod, as notices and warnings are not turned into ErrorException exceptions there.
Code must not be written by assuming that the error handler has this behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, currently the session write fails silently in production.
I updated the code to check the last error message and throw a E_USER_WARNING with the corrected message. However, the warning is not logged by default.
Alternatively, we can throw an Excpetion if the write fails, as it is an error anyway. However, it does break BC.
Status: needs work |
Instead of relying on some external error handler to trigger the exception, I'd suggest to register a temporary error handler that does the throw. |
That is a good idea! The code is much cleaner now. |
$handler = $handler->getHandler(); | ||
} | ||
|
||
$message = sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be inlined in the trigger_error()
call
Thank you @digilist. |
… (digilist) This PR was submitted for the 2.8 branch but it was merged into the 3.3-dev branch instead (closes #21421). Discussion ---------- Use proper error message when session write fails #20807 This improves the error message that is thrown if a session write fails (see #20807) As there was no way to get the actual handler, I introduced a method on the SessionHandlerProxy. I hope that's okay, otherwise please give me a hint on what to do. | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20807 | License | MIT Commits ------- c7a44be Use proper error message when session write fails #20807
This improves the error message that is thrown if a session write fails (see #20807)
As there was no way to get the actual handler, I introduced a method on the SessionHandlerProxy. I hope that's okay, otherwise please give me a hint on what to do.