Skip to content
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

Unable to set 'session.gc_maxlifetime' #231

Open
krasa opened this issue Dec 8, 2023 · 0 comments
Open

Unable to set 'session.gc_maxlifetime' #231

krasa opened this issue Dec 8, 2023 · 0 comments

Comments

@krasa
Copy link

krasa commented Dec 8, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant