We recently migrated to Moodle 3.9 and now I see a lot of these messages in the error_log of Apache:
"Cannot find session record gpnlpm82gj4actn83389s5othb for user 33332, creating new session."
What could be the cause of these messages? We don't get complaints of our users that their sessions are lost while following courses. We use PHP 7.2 and I configurated Redis caching server for sessions in the Moodle config. No problems in Moodle 3.5.14 (our previous version).
Messages 'Cannot find session record x for user x, creating new session.'
by Alain Raap -
Number of replies: 2
In reply to Alain Raap
Re: Messages 'Cannot find session record x for user x, creating new session.'
by Howard Miller -
I think this is an artefact of using Redis for sessions. We get those messages too but it does not seem to cause any issues.
We'd definitely have heard if users were getting timed out prematurely.
We'd definitely have heard if users were getting timed out prematurely.
In reply to Howard Miller
Re: Messages 'Cannot find session record x for user x, creating new session.'
by Alain Raap -
Thanks Howard for your explanation. I checked the code that throws the error and thought it might be a problem,
this is the code snippet of lib/classes/session/manager.php I found:
*
* @param bool $newsid is this a new session in first http request?
*/
protected static function initialise_user_session($newsid) {
global $CFG, $DB;
$sid = session_id();
if (!$sid) {
// No session, very weird.
error_log('Missing session ID, session not started!');
self::init_empty_session();
return;
}
if (!$record = $DB->get_record('sessions', array('sid'=>$sid), 'id, sid, state, userid, lastip, timecreated, timemodified')) {
if (!$newsid) {
if (!empty($_SESSION['USER']->id)) {
// This should not happen, just log it, we MUST not produce any output here!
error_log("Cannot find session record $sid for user ".$_SESSION['USER']->id.", creating new session.");
}
// Prevent session fixation attacks.
session_regenerate_id(true);
}
$_SESSION = array();
}
unset($sid);
this is the code snippet of lib/classes/session/manager.php I found:
*
* @param bool $newsid is this a new session in first http request?
*/
protected static function initialise_user_session($newsid) {
global $CFG, $DB;
$sid = session_id();
if (!$sid) {
// No session, very weird.
error_log('Missing session ID, session not started!');
self::init_empty_session();
return;
}
if (!$record = $DB->get_record('sessions', array('sid'=>$sid), 'id, sid, state, userid, lastip, timecreated, timemodified')) {
if (!$newsid) {
if (!empty($_SESSION['USER']->id)) {
// This should not happen, just log it, we MUST not produce any output here!
error_log("Cannot find session record $sid for user ".$_SESSION['USER']->id.", creating new session.");
}
// Prevent session fixation attacks.
session_regenerate_id(true);
}
$_SESSION = array();
}
unset($sid);