Skip to content

Bug: All database handler sessions lost during garbage collection, if $sessionExpiration set to 0  #4169

@nmolinos

Description

@nmolinos

Describe the bug
When using the Database Session handler and setting $sessionExpiration to 0 in App.php, all sessions are effectively lost when the garbage collector runs.

CodeIgniter 4 version
Current version (4.0.4)

Affected module(s)
DatabaseHandler

return ($this->db->table($this->table)->delete('timestamp < ' . (time() - $maxlifetime))) ? true : $this->fail();

Expected behavior, and steps to reproduce if appropriate
This can be seen more easily by setting session.gc_divisor to 1 in php.ini after setting $sessionExpiration to 0. Any stored sessions in the ci_session table are lost after navigating to another CI controller.

Would expect the sessions to stay alive per this:

* Setting to 0 (zero) means expire when the browser is closed.

Not entirely sure how garbage collection should be handled on them, though.

Context

  • OS: Windows 10
  • Apache 2.4.46
  • PHP version 7.3.21

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions