?
avatar enesbil
enesbil
10 Jan 2016

Since the last update, I get very often the following error:
Error initialising the session.

With the following Call-Stack:
Call stack # Function Location
1 JApplicationCms->execute() /var/www/joomla/index.php:52
2 JApplicationSite->doExecute() /var/www/joomla/libraries/cms/application/cms.php:252
3 JApplicationSite->initialiseApp() /var/www/joomla/libraries/cms/application/site.php:209
4 JApplicationCms->initialiseApp() /var/www/joomla/libraries/cms/application/site.php:663
5 JApplicationBase->triggerEvent() /var/www/joomla/libraries/cms/application/cms.php:654
6 JEventDispatcher->trigger() /var/www/joomla/libraries/joomla/application/base.php:106
7 JEvent->update() /var/www/joomla/libraries/joomla/event/dispatcher.php:160
8 call_user_func_array() /var/www/joomla/libraries/joomla/event/event.php:69
9 PlgSystemRemember->onAfterInitialise()  
10 JApplicationSite->login() /var/www/joomla/plugins/system/remember/remember.php:58
11 JApplicationCms->login() /var/www/joomla/libraries/cms/application/site.php:694
12 JApplicationBase->triggerEvent() /var/www/joomla/libraries/cms/application/cms.php:849
13 JEventDispatcher->trigger() /var/www/joomla/libraries/joomla/application/base.php:106
14 JEvent->update() /var/www/joomla/libraries/joomla/event/dispatcher.php:160
15 call_user_func_array() /var/www/joomla/libraries/joomla/event/event.php:69
16 PlgUserJoomla->onUserLogin()  
17 JApplicationCms->checkSession() /var/www/joomla/plugins/user/joomla/joomla.php:216

I have a highly frequent used site, and since I log every error, this error occures very often. 2000-4000 times a day, sometimes even I am affected. It happens very unregular. After I refresh the site, it works again.

Steps to reproduce the issue

Visit site after the session is expired.

Expected result

You are logged in, page works fine.

Actual result

You get an error-message.

System information (as much as possible)

Latest Joomla Version. This error started after the last update.
PHP erstellt für Linux CZ17 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u1 (2015-12-14) x86_64
Datenbankversion 5.5.46-0+deb8u1-log
Datenbankzeichensatz utf8_general_ci
PHP-Version 5.6.14-0+deb8u1
Webserver nginx/1.6.2
PHP-Interface für den Webserver fpm-fcgi
Joomla!-Version Joomla! 3.4.8 Stable [ Ember ] 24-December-2015 19:30 GMT
Joomla!-Plattform-Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
Browsererkennung Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Additional comments

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar enesbil enesbil - open - 10 Jan 2016
avatar ggppdk
ggppdk - comment - 10 Jan 2016

SQL Insertion query into the session table fails

  • the actual SQL error message is needed, but unfornately the message does not incude the SQL error (or other error database driver error)

Temporarily, until you get the error to occur again, edit file:
libraries/cms/application/cms.php

about line 212, find

throw new RuntimeException(JText::_('JERROR_SESSION_STARTUP'));

exactly above it (and inside the catch block) add line:

jimport('joomla.log.log');
JLog::addLogger(array('text_file' => 'session_errors.php'));
JLog::add(JText::_('JERROR_SESSION_STARTUP').' '.$db->getErrorMsg());

then wait unitil error occurs and this file is created:
.../joomla_folder/logs/session_errors.php

hopefully the SQL error is there ?

avatar enesbil
enesbil - comment - 10 Jan 2016

Thanks for your help!

I don't know why this is happening, but it seems empty session-ids are causing this issue:
Error initialising the session. Duplicate entry '' for key 'PRIMARY' SQL=INSERT $
(session_id, client_id, guest, time, userid, username) VALUES
('', 0, 1, '0', 0, '')

I will look, how to solve this issue.

avatar enesbil
enesbil - comment - 10 Jan 2016

Adding the following code snippet:

if($session->getId() == ''){
    $session->restart();
}

right after

$session = JFactory::getSession();

in libraries/cms/application/cms.php solved this issue. Although I have not changed any core code, I could not found any further information about this issue on google or the issue tracker. There is a possibility for some individual code in my components/plugins which causes this issue.

avatar ggppdk
ggppdk - comment - 10 Jan 2016

It could a Joomla bug, if the session is not in "active" state ?

Temporarily please revert your change, and try at the same place as descibe above:

  jimport('joomla.log.log');
  JLog::addLogger(array('text_file' => 'session_errors.php'));
  JLog::add(
    JText::_('JERROR_SESSION_STARTUP').
    ' Session State: '.$session->getState().
    ' Sql Error: '.$db->getErrorMsg()
  );

then after error occurs search in the file for "Session State"

avatar enesbil
enesbil - comment - 10 Jan 2016

Hello,
here's the log:

Error initialising the session.
Session State: destroyed
Sql Error: Duplicate entry '' for key 'PRIMARY' SQL=INSERT INTO joomla_session
(session_id, client_id, guest, time, userid, username) VALUES
('', 0, 1, '0', 0, '')

Hope this helps.

avatar ggppdk
ggppdk - comment - 11 Jan 2016

JFactory::getSession();
will call JSession::createSession()

  • which only check if session is empty because of being "expired" and then it restarts it
if ($session->getState() == 'expired')
{
    $session->restart();
}

it does not restart the session if is "destroyed"
maybe (or maybe NOT) it needs:

$state = $session->getState();
if ($state== 'expired' || $state=='destroyed') {
    $session->restart();
}

but i don't know why session is destroyed in the first place

  • i think a session is destroyed on logout or when JSession::start/restart finds it to be invalid

there is a PHP bug effecting PHP 7 , PHP 5.5. and PHP 5.4 ?
that causes

session_regenerate_id(true);

to randomly generates a warning and lose session data

i mention it because you are high traffic and you have it randomly, (you can not find some specific actions to reproduce it, instead you must wait for it to happen randomly ?)

i don't have enough knowledge with JSession to say much more

avatar enesbil
enesbil - comment - 11 Jan 2016

Unfortunately, I could not reproduce this issue. Nevertheless it also happened to me 1-2 times. I can not predict or say it's random: sometimes ~1000 times in less than 5 minutes and then only ~1000 in several hours.

I'm going to further investigate this issue.

avatar N6REJ
N6REJ - comment - 11 Jan 2016

I don't know if this is related but the last several times I've let a
session time out in my clean 3.4.8 install when the login prompt comes
up and I log in it tells me the session expired and forces me to log in
again.
Bear

On 1/11/2016 04:57, enesbil wrote:

Unfortunately, I could not reproduce this issue. Nevertheless it also
happened to me 1-2 times. It happens really random, sometimes ~1000
times in less than 5 minutes and then only ~1000 in several hours.

I'm going to further investigate this issue.


Reply to this email directly or view it on GitHub
#8871 (comment).

avatar mcassisa
mcassisa - comment - 12 Feb 2016

I am experiencing problem with session instantiation with a third party cakephp application that loads the joomla mainframe to allow SSO using joomla logged in user data (as described here). I got a blank page in the cakephp just saying "Application Instantiation Error: Error initialising the session". No errors were logged
It seems that the solution proposed in the comment by ggppdk solved the issue, but the core joomla file has to be edited, which is obviouslly not fine at all.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8871.

avatar brianteeman brianteeman - change - 8 Apr 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-04-08 14:06:52
Closed_By brianteeman
avatar brianteeman brianteeman - close - 8 Apr 2016
avatar brianteeman brianteeman - close - 8 Apr 2016
avatar brianteeman
brianteeman - comment - 8 Apr 2016

I am closing this issue at this time. The session code has had a lot of changes since this issue was reported so it might have been resolved by those changes. If you are still having an issue with the current release please create a new issue. Thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8871.

avatar RaimisErvit
RaimisErvit - comment - 4 Aug 2016

when update to 3.6.0 i have this problem. and sometimes user get information with no login... i get three different errors on same way:

1062 Error initialising the session.
or
The most recent request was denied because it contained an invalid security token. Please refresh the page and try again.
or
Error displaying the error page: Application Instantiation Error: Error initialising the session.

avatar Kunal0143
Kunal0143 - comment - 11 Mar 2017

Hello,

I am using joomla 3.6.0 version and i am still getting the same error, when i refresh the page it start working fine..

Can you please help me where i need to update to fix this error ?

Thanks

avatar vanoir
vanoir - comment - 29 Jun 2017

I'm having the same problem as Kunal0143 above. I don't know why but my dev doesn't reproduce the error.

avatar brianteeman
brianteeman - comment - 29 Jun 2017

No one will see a comment on a closed issue.

Add a Comment

Login with GitHub to post a comment