Auto logout causes session variables to be deleted

Created on 26 April 2022, over 3 years ago
Updated 5 August 2025, about 2 months ago

Problem/Motivation

When Auto Logout is enabled, custom session variables are deleted for logged in users only.

Steps to reproduce

  1. Enable auto log out
  2. When logged in, set a session variable (see below)
  3. Check the session variable during a separate request (see below)

Set a session variable

$session = \Drupal::request()->getSession();   
$session->set('my_module.my_variable', 'Test data');

Check session variable

$session = \Drupal::request()->getSession();   
if (!$session->has('my_module.my_variable')) {
  \Drupal::logger('my_module')->notice('Found session variable.');
}
else {
  \Drupal::logger('my_module')->notice('Session variable not found.');
}

Proposed resolution

Found out what's causing the problem and fix it.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇦🇺Australia imclean Tasmania

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Pipeline finished with Success
    about 2 months ago
    Total: 446s
    #565215
  • 🇸🇮Slovenia deaom

    I can't reproduce the issue with the updated code (session done via requestStack and current session). I also think the solution could possible cause issues when JS triggers the request as it returns nothing basically and skips the whole sessions set up. Leaving to needs review with the rebased MR, so somebody else can confirm if solution is still needed.

Production build 0.71.5 2024