-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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] Redis - write_close_session #7695
Comments
What is the exact error message? It would be helpful if you could show a minimal working sample code to reproduce the error. |
Not exactly my case but very close: Just create 2 functions in your controller and call one after the other in browser (or uncomment the redirect line): public function debug1()
{
$session = \Config\Services::session();
$session->start();
$session->set("test","hola");
session_write_close();
$session = \Config\Services::session();
$session->start();
print_r($_SESSION, false);
session_write_close();
//return redirect()->redirect( base_url('home/debug2'));
}
public function debug2()
{
$session = \Config\Services::session();
$session->start();
print_r($_SESSION, false);
session_write_close();
} |
Out off the topic, how do I make sure the session store the data into Redis is working? Because all operations of the session are performed normally after I set up the redisHandler in Config, but I find that there is no data stored in Redis. |
@gabriel-joy Try #7887 |
Yes, it's working as expected. Do you know when this fix will be published in the official release? |
@gabriel-joy Thank you for testing! |
@kenjis There is a performance issue with this fix. My guess is the session is locked and all calls are sequential, session_write_close() not closing the session. |
The performance issue is really because of the fix? |
how could I know? I will open a new bug and hopefully someone will find out. |
Revert the change: https://github.com/codeigniter4/CodeIgniter4/pull/7887/files#diff-1a7b1fe40ddc58f0b240a268889a1952778b0631ce9db5f54cddaa359429dd60 |
I updated the script for performance tests, it seems that performance is not affected. Bot requests are executed in parallel not waiting for each other. Here is the updated test code: public function debug1()
{
$benchmark = \Config\Services::timer();
$benchmark->start('read session1');
$session = \Config\Services::session();
$session->start();
$session->set("test","hola");
session_write_close();
sleep(5);
$session = \Config\Services::session();
$session->start();
print_r($_SESSION, false);
session_write_close();
$benchmark->stop('read session1');
$timers = $benchmark->getTimers();
echo('Session read length:'.$timers['read session1']['duration'].'s');
}
public function debug2()
{
$benchmark = \Config\Services::timer();
$benchmark->start('read session2');
$session = \Config\Services::session();
$session->start();
print_r($_SESSION, false);
session_write_close();
$benchmark->stop('read session2');
$timers = $benchmark->getTimers();
echo('Session read length:'.$timers['read session2']['duration'].'s');
} |
PHP Version
8.2
CodeIgniter4 Version
4
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
switching session filehandler to redis handler works as exepected as long as I'm not using session_write_close.
calling session_write_close in the same script works fine but in ajax calls I get an empty session.
after session_write_close, session->destroy() generate an exception as well
Steps to Reproduce
set in
public $sessionDriver = 'CodeIgniter\Session\Handlers\RedisHandler';
public string $sessionSavePath = 'tcp://localhost:6379?database=10'
set session variable in main script
call session_write_close()
3. make an ajax call and check session variables.
Expected Output
to work like file handler
Anything else?
No response
The text was updated successfully, but these errors were encountered: