Skip to content

Unable to set 'session.gc_maxlifetime'  #231

Open
@krasa

Description

@krasa

Version: nette/http v3.2.2

Bug Description

gc_maxlifetime calculation is inaccurate, causing rare random errors:

Nette\InvalidStateException: Unable to set 'session.gc_maxlifetime' to value '1209599' when session has been started by session.auto_start or session_start().
Nette\InvalidStateException: Unable to set 'session.gc_maxlifetime' to value '1209600' when session has been started by session.auto_start or session_start(). 

config.neon:

session:
  expiration: 14 days 

Stack:

Session.php:460, Nette\Http\Session->configure()
Session.php:426, Nette\Http\Session->setOptions()
Session.php:516, Nette\Http\Session->setExpiration()
Container_b8ee45f4b9.php:2205, Container_b8ee45f4b9->createServiceSession__session()
Container.php:210, Nette\DI\Container->createService()
Container.php:126, Nette\DI\Container->getService()
Container_b8ee45f4b9.php:2245, Container_b8ee45f4b9->{closure:D:\_C\xampp\htdocs\...}()
Container_b8ee45f4b9.php:2246, Container_b8ee45f4b9->initialize()
Configurator.php:243, Nette\Bootstrap\Configurator->createContainer()
index.php:7, {main}()

Or maybe something else is wrong, because it may have started after manually starting sessions in our OAuth login presenter:

  public function renderOauth()
  {
    if (!$this->getSession()->exists())
    {
      // https://diskuse.jakpsatweb.cz/?action=vthread&forum=9&topic=128222#6
      ini_set("session.gc_maxlifetime", self::SESSION_GC_MAXLIFETIME); //14 * 24 * 60 * 60 = 1209600

      //fixes: Undefined global variable $_SESSION
      $this->getSession()->start();
    }
    ...
  }

Possible Solution

  • fix the expiration time calculation
  • add ini_get("session.$key") to that exception message, for easier diagnostics

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions