bwdutton / gallery3

The simplest, most intuitive way to host your photos on your website.
https://galleryrevival.com/
GNU General Public License v2.0
131 stars 26 forks source link

session_write_close() error in theme Gray Dragon #25

Open stefanofornari opened 1 year ago

stefanofornari commented 1 year ago

Hello

I have recently upgraded Gallery to the main branch and I have now a problem with the theme Gray Dragon. The exception I see in the server log is:

PHP Fatal error:  Uncaught ErrorException: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /opt/tomcat7/temp) in /opt/Campanile/src/main/webapp/system/libraries/Session.php:325
Stack trace:
#0 [internal function]: gallery_error_Core::error_handler()
#1 /opt/Campanile/src/main/webapp/system/libraries/Session.php(325): session_write_close()
#2 /opt/Campanile/src/main/webapp/system/core/Event.php(208): Session_Core->write_close()
#3 /opt/Campanile/src/main/webapp/system/core/Kohana.php(524): Event_Core::run()
#4 [internal function]: Kohana_Core::shutdown()
#5 {main}
  thrown in /opt/Campanile/src/main/webapp/system/libraries/Session.php on line 325

PHP Fatal error:  Uncaught ErrorException: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /opt/tomcat7/temp) in /opt/Campanile/src/main/webapp/system/libraries/Session.php:325
Stack trace:
#0 [internal function]: gallery_error_Core::error_handler()
#1 /opt/Campanile/src/main/webapp/system/libraries/Session.php(325): session_write_close()
#2 /opt/Campanile/src/main/webapp/system/core/Event.php(208): Session_Core->write_close()
#3 /opt/Campanile/src/main/webapp/system/core/Kohana.php(524): Event_Core::run()
#4 [internal function]: Kohana_Core::shutdown()
#5 {main}
  thrown in /opt/Campanile/src/main/webapp/system/libraries/Session.php on line 325

And it happens not always, but once in a while navigating the site.

I am using php 8


PHP 8.1.2-1ubuntu2.10 (cli) (built: Jan 16 2023 15:19:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.10, Copyright (c), by Zend Technologies

With the default theme I do not see the problem. I am starting to dig into the code, although I am not a php developer; any help is appreciated. Let me know if there are other places where I can get some support.

thanks in advance

stefanofornari commented 1 year ago

I actually found out the issue is there for all themes. After some research I ran into this: https://stackoverflow.com/questions/43636109/php7-session-warning-session-write-close/43636110#43636110

which tells me it is something in php7 and earlier itself.

For now I have applied the workaround below, I have no idea of the implications though :)

system/libraries/Session.php
325,326c325
<           try { session_write_close(); }
<           catch (Throwable $t) { error_log('error in session_write_close() - see https://stackoverflow.com/questions/43636109/php7-session-warning-session-write-close/43636110#43636110'); }
---
>           session_write_close();
328,329d326
<       
<       return TRUE;