-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
BUG: session_write_close(): Failed to write session data using user defined save handler. Localised with suggested fix #6276
Comments
TESTING UPDATE - 100% REPRODUCABLE. I've managed to replicate the error by doing the following:
|
RESEARCH OF POSSIBLE CAUSEper https://stackoverflow.com/questions/34117651/php7-symfony-2-8-failed-to-write-session-data, and https://forum.codeigniter.com/thread-80404.html Make sure the write method of your session handler returns bool - true on success. The php session_set_save_handler documentation doesn't mention this. It is however mentioned in the SessionHandlerInterface documentation: The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing. PHP7 is more strict with session handling for custom session handlers. Symfony's custom session handler for its write method is, for whatever reason, returning false. Previously this did not trigger an error but now it does. In earlier versions of PHP, returning nothing did not result in an error. Since PHP 7.0, returning nothing results in the error: Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp). https://stackoverflow.com/questions/37707905/php7-symfony-3-1-0-vagrant-failed-to-write-session-data |
UNRESOLVEDThis removed the error - but also stops CI from generating session data.
Results: Bug resolved- but no more session data getting stored in ci_sessions table COMMENTS
HOWEVER, that still means the custom session handler is lacking adequate handling to a FALSE response from the SessionHandlerInterface. I understand CI3 is retired. It still works well for me, so I am not interested in migrating to CI4, but I will make some customised changes to the session handling class to better deal with FALSE coming from the session handler. If anyone at CI central has some ideas on how to best do this, please let me know Thanks |
@gidzr can't reproduce php 8.1.17 (8.1.2 also) + nginx 1.18.0 + mysql 8.0.34
show create table
check your php + db driver logs (looks like you have issues with inserting values into db - mb deadlock?) |
@gidzr Are you able to reproduce your issue on a clean system (see #6247 (reply in thread) ) |
Hey @bunglegrind .. I've had to workaround it for now. I'll have to resolve this later though and will get back to you when I can try and reproduce. If I stumble on the issue / fix I'll also post back. |
@bunglegrind Is it related to this #5703 ? |
No idea. I was never able to reproduce the issue. |
@bunglegrind and @jamieburchell - thanks for checking in and keeping up with this.. I'll look into the linked issue and retest, but will not have time until year-end. But I'll certainly aim to get back to this. |
Hi
ISSUE
I've been getting this ongoing warning / error: "session_write_close(): Failed to write session data using user defined save handler".
This has been intermittent but ongoing, ie. every 5 reloads or so.
TESTING
After checking session_write_close, output buffering, all instances of session_start()/etc I only STUMBLED onto the source of this issue, after updating my error handling function AND turning output buffering off in php.ini to get specific visibility over previously suppressed warnings, which exposed a range of issues in "system\libraries\Session\Session.php".
The issues listed below are mostly related to "ini_set()" with one each for session save handler and session_start after headers sent. NOTE: I am aware that these issues are triggered by the output buffering being off, BUT there is some relationship between these items in the session handler, the errors received when the buffer is off, and the save_handler issues.
That is, after commenting each of these out and turning the output buffering back on (4096), the "session_write_close(): Failed to write session" cleared up.
My concern is that these lines are supposed to be doing something useful and commenting out lines is not a solution, just a method to troubleshoot.
QUESTIONS
Potential Fixes ? (big question mark)
Adding a test to the ini_set lines.. something like..
would this fix be consistent with the code? is ini_set only supposed to be set prior to initiation of session and therefore a session test works well?
or alternately..
do I need to ensure a session name has been set irrespective of session state?
or is it both?
Please let me know what approach would be the healthiest least downstream unintended consequence fix.
Thanks
SUMMARY OF FINDINGS
ERRORS AND CODE
__construct()
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] session_set_save_handler(): Session save handler cannot be changed after headers have already been sent on line 110 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] session_start(): Session cannot be started after headers have already been sent on line 138 in file ..\Session.php
_configure()
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 304 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent on line 335 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 356 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 366 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 367 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 368 in file ..\Session.php
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 369 in file ..\Session.php
// Security is king
:: CommonHelper Error Logger (set_error_handler section) ::--> [2] ini_set(): Session ini settings cannot be changed after headers have already been sent on line 427 in file ..\Session.php
The text was updated successfully, but these errors were encountered: