PHP message: Cannot find session record "x" for user "X", creating new session

PHP message: Cannot find session record "x" for user "X", creating new session

by Job Céspedes Ortiz -
Number of replies: 4
Picture of Plugin developers

Using:

Moodle 2.7.1+, Apache, Postgres

When running jmeter test (M), I got a few errors (0.04% or 0.01%). When searching in the logs, I found the following in apache error:

"FastCGI: server "/fcgi-bin-php5-fpm" stderr: PHP message: Cannot find session record t8nscmvolp6nepd26gd0n76s27 for user 200, creating new session"

I've tried using memcached session driver and, with fewer ocurrencies, file session driver.

Any Ideas?

Thanks

Average of ratings: -
In reply to Job Céspedes Ortiz

Re: PHP message: Cannot find session record "x" for user "X", creating new session

by James McLean -

We've been having this issue for a very long time and have invested significant time into finding the cause. No luck yet, though! We run a cluster and use memcache sessions exclusively. Our investigation has not yielded any information into a possible cause - but based on the error the session disappears from the Database - which shouldn't just occur out of the blue as it has been. We see these lost sessions every few minutes.

This is a fairly large point of contention for our users as sessions are being lost somewhere and we're at a loss to explain it or resolve the problem.

[05-Dec-2014 14:42:07 <TZ>] Cannot find session record sr93250ucid27190ubnj6l1u80 for user 78950, creating new session.
[05-Dec-2014 14:43:26 <TZ>] Cannot find session record a4enol8u84cgv16a6969v5ph43 for user 136845, creating new session.
[05-Dec-2014 14:44:42 <TZ>] Cannot find session record rsn4nm1v65cc69ct3r2a1kder7 for user 36781, creating new session.
[05-Dec-2014 14:46:03 <TZ>] Cannot find session record djv1lft3mku377umiqrtatm105 for user 156178, creating new session.
[05-Dec-2014 14:48:45 <TZ>] Cannot find session record f6cb5v8jhqr7q0bvvhgtc2qe91 for user 43111, creating new session.
[05-Dec-2014 14:48:51 <TZ>] Cannot find session record hvm5fart0bs5v91rbtdvpp0is0 for user 73140, creating new session.
[05-Dec-2014 14:52:24 <TZ>] Cannot find session record kem8mf71pn5k1qslc6ik5a3bh7 for user 77561, creating new session.
[05-Dec-2014 14:52:38 <TZ>] Cannot find session record 9nc50t4fs9dqqef3hm4monj3m4 for user 72156, creating new session.
[05-Dec-2014 14:53:05 <TZ>] Cannot find session record nivofvkuhlekc8blb42qt8r5f6 for user 58532, creating new session.
[05-Dec-2014 14:53:09 <TZ>] Cannot find session record 412145e36fvuuisdg0rq2o0ba3 for user 71665, creating new session.
[05-Dec-2014 14:55:43 <TZ>] Cannot find session record 350ahss74h9iagf0i89ci8l4l5 for user 141127, creating new session.
[05-Dec-2014 14:55:48 <TZ>] Cannot find session record nuq7al03d661snrn57t02r9ir4 for user 74293, creating new session.
[05-Dec-2014 14:55:58 <TZ>] Cannot find session record clhnf10f13fhe40qb9dqmvisl3 for user 1, creating new session.
[05-Dec-2014 14:56:14 <TZ>] Cannot find session record 3amqjv2sfvdco82r07fdac1gg3 for user 60556, creating new session.
[05-Dec-2014 14:58:22 <TZ>] Cannot find session record 11ripmuhg7d3cmr4jcv4dg9nk1 for user 157518, creating new session.
[05-Dec-2014 14:58:44 <TZ>] Cannot find session record uu61hu0unvq7dhd9r1tp3mtje2 for user 2274, creating new session.
[05-Dec-2014 14:59:25 <TZ>] Cannot find session record 5t5c10d1j5nelt0hr4tjdp83q5 for user 55859, creating new session.
[05-Dec-2014 14:59:40 <TZ>] Cannot find session record 50e3lr3moahg6mdds3ilq61nc7 for user 75715, creating new session.
[05-Dec-2014 15:00:02 <TZ>] Cannot find session record 94cvn1aijkiibnu78ronk9odj0 for user 156638, creating new session.
[05-Dec-2014 15:01:23 <TZ>] Cannot find session record 1eska6tia484b0ve5n5dg2bik1 for user 48902, creating new session.
[05-Dec-2014 15:02:05 <TZ>] Cannot find session record tbkhsqdmhsrhm6p5pk01p909o4 for user 64287, creating new session.
[05-Dec-2014 15:02:50 <TZ>] Cannot find session record n5811io5tmm2crqi6bsrlf8qk7 for user 51262, creating new session.
[05-Dec-2014 15:04:14 <TZ>] Cannot find session record qvlkb5s4503b53339q8rgbs8v5 for user 148396, creating new session.
[05-Dec-2014 15:05:27 <TZ>] Cannot find session record ck7hj470k7ek4d6uhn4upf4is1 for user 50199, creating new session.
[05-Dec-2014 15:05:41 <TZ>] Cannot find session record l0et150olg0jbijacivf9i68p7 for user 7609, creating new session.
[05-Dec-2014 15:09:23 <TZ>] Cannot find session record 10dkj593bpaifq6nti057iilj3 for user 16100, creating new session.
[05-Dec-2014 15:09:58 <TZ>] Cannot find session record a16685dkvmd9s71tfdra1sbtu7 for user 26690, creating new session.
[05-Dec-2014 15:11:38 <TZ>] Cannot find session record 8kfr70obnnlpl50bs3r0u02q61 for user 61711, creating new session.


Average of ratings: Useful (1)
In reply to James McLean

Re: PHP message: Cannot find session record "x" for user "X", creating new session

by Benjamin Seclier -
Hello James and Job,
I had the same problem here (we are in moodle 2.6.8). This problem is due to this line in the /lib/classes/session/manager.php file :

ini_set('session.gc_maxlifetime', 60*60*24*4);

Indeed, this line forces the max session lifetime to 4 days. You have to replace it with this line :

ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);

The $CFG->sessiontimeout is set in the admin panel (/admin/settings.php?section=sessionhandling).

With this patch, logs are gone smile
Hope it helped !

Regards,

Average of ratings: Useful (2)
In reply to James McLean

Re: PHP message: Cannot find session record "x" for user "X", creating new session

by Rex Lorenzo -

We started getting the same error message in our PHP error_log numbering in the thousands. It started happening after we upgraded from Moodle 2.7.3 to 2.7.7. Before then, if we did get this error it would only be 2 or 3 instances.

In the code the comment says "This should not happen, just log it, we MUST not produce any output here!"

Why shouldn't that part of the code execute and what does it mean that the code got there? I am reading it as that the user reached the session time limit and tried accessing a page, or does it mean something else? If it means the way I am reading it, it shouldn't be that rare...

Also, we have database sessions turned off, but why is it still checking the mdl_sessions table?

Average of ratings: Useful (1)
In reply to Rex Lorenzo

Re: PHP message: Cannot find session record "x" for user "X", creating new session

by James McLean -

When database sessions are turned off, the existence of sessions is still tracked using the <prefix>_sessions table, but the session data is not stored there. Locking of the rows for update is significantly less clearly so performance is not a worry.

Average of ratings: Useful (1)