DB Error: Duplicate entry 'xxxxxx' for key 'sessions_pkey'

@asmecher,

I enabled the debug on and show stats on and here is the stack trace, It seems it is trying to insert, not sure whether it is the expected behaviour:

(mysql): SET NAMES ‘utf8’
(mysql): INSERT INTO sessions (session_id, ip_address, user_agent, created, last_used, remember, data, domain) VALUES (‘cuff3emf3rirk9qtkubgnlp6o5’, ‘122.172.129.23’, ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36’, 1497097561, 1497097561, 0, ‘’, ‘ayushdhara.in’)
1062: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’
ADOConnection._Execute(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
('cuff3…) % line 845, file: adodb.inc.php
ADOConnection.Execute(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
(?, ?, …, Array[8]) % line 226, file: DAO.inc.php
DAO.update(INSERT INTO sessions
(session_id, ip_address, user_agent, created, last_used, remember, data, domain)
VALUES
(?, ?, …, Array[8]) % line 88, file: SessionDAO.inc.php
SessionDAO.insertSession(Object:Session) % line 91, file: SessionManager.inc.php
SessionManager.SessionManager(Object:SessionDAO, Object:Request) % line 130, file: SessionManager.inc.php
DB Error: Duplicate entry ‘cuff3emf3rirk9qtkubgnlp6o5’ for key ‘sessions_pkey’

Stack Trace:

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionDAO.inc.php line 88
Function: DAO->update(“INSERT INTO sessions (session_id, ip_address, user_agent, cr…”, Array(8))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionManager.inc.php line 91
Function: SessionDAO->insertSession(Object(Session))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/session/SessionManager.inc.php line 130
Function: SessionManager->SessionManager(Object(SessionDAO), Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/classes/security/Validation.inc.php line 379
Function: SessionManager->getManager()

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/PKPPageRouter.inc.php line 66
Function: Validation->isLoggedIn()

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/Dispatcher.inc.php line 117
Function: PKPPageRouter->isCacheable(Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/lib/pkp/classes/core/PKPApplication.inc.php line 178
Function: Dispatcher->dispatch(Object(Request))

File: /var/www/tangenti/data/www/ayushdhara.in/index.php line 64
Function: PKPApplication->execute()

Please let me know if something can be observed here to fix the issue.

Note:
Made it as Under Maintenance for now not to show errors to customers.

Hi @Umadhar,

Hmm, this is strange behavior – I’d suggest changing session_cookie_name in config.inc.php to something else to eliminate old cookies / cookie path changes as a cause. Make sure your session_cookie_path is set appropriately – it looks like you’re behind a reverse proxy, so this may be necessary. Anytime you change something in your configuration and want to test it, make sure you’re erasing the relevant cookie from your browser.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

Yes Really taking my time and killing me this issue. What if we make the session_id from sessions table makes non unique, does it harm anything.

I am trying your suggestions. What is the problem with the Reverse proxy, how do we resolve if that is the issue?

Hi @Umadhar,

The session ID needs to be unique – removing the constraint won’t resolve the problem.

If possible, I would suggest trying to access OJS without the reverse proxy being in the way. Unfortunately I can’t give you specifics on how to do this because there are many possible proxy configurations, but within our hosting environment here at SFU, it would normally mean accessing the hosting server directly (possibly at a different IP address and port than your front-facing proxy uses).

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher ,

I changed the session.save_path but it is not working but saying the folder needs to have permissions to write which i gave as 757 too. Please find the errors and stack trace on the portal directly:

http://ayushdhara.in/

With regards to Reverse proxy, if i take the dedicated IP Address, this will become direct access. If this is wrong understanding please let me know what is meant by direct OJS access?

One more question: in the sessionManager.inc.php do i need to make any chagnes to the following one at line 42:

ini_set(‘session.cookie_path’, $request->getBasePath() . ‘/’);

Attached a screenshot for your reference that the sessions are being written in the sessions/ folder as well but still the error being thrown.

Hi @Umadhar,

OJS configures PHP to use database-backed sessions (in the sessions table). It looks like your PHP configuration is for some reason still attempting to create file-based sessions. I suspect the cause of this is somewhere in your PHP configuration, but unfortunately I can’t spot it in the phpinfo() output you posted above. You might try something like StackOverflow to get hints on where to look.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

Based on the session.save_path the sessions are being stored in that folder which i set as per your instruction. Just wanted to understand, when the sessions are being managed through the database-blackened sessions, why do we need to worry about the session.save_path?

What i observed is, This is storing in the database as well as in the file based, not sure why and what is happening.

There is some setting which is causing problem for the sessions to set $this->userSession in SessionManager.inc.php if we come to know about it the issue will be fixed. You might have received lot of questions on this if you know already that would be great help and save my days…

Will the dedicated IP Address works for the reverse proxy issue?

Thank you for your responses and appreciate it.

Thanks and Regards,
Umadhar

Hi @Umadhar,

The session save path isn’t the setting I referenced. I was talking about a differently-named setting in config.inc.php, not php.ini.

If you see sessions being saved in the filesystem as you attempt to access OJS, then some aspect of your PHP configuration is preventing OJS from managing its own sessions, leading to the problem you describe. It appears to be something non-standard or unusual, and I’m afraid I’m not going to be able to debug it remotely. I would suggest talking with your server admin or inquiring on Stackoverflow.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

@asmecher,

Let me explain you:

session_cookie_name : I changed it.

session_cookie_path:
I searched the entire config.inc.php for the session.cookie_path i did not find any, i tried with path, cookie and session words search. So i set it in the .htaccess. If you think particular config parameter/variable please let me know that will help.

I do not see any change after it.

Please guide me on this…

Hi @Umadhar,

It’s session_cookie_path, not session.cookie_path.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Yes, it was my typo, I made changes to session.cookie_path. only.

Any other valuable suggestions? What about on the dedicated IP address to access directly?

I am going to do new installation of the OJS 2.4.7-1 to see if there is any reverse proxy issue to see how it works and come back, So that we can nail this down.

Thanks you and have a good night.

Hi @Umadhar,

You wrote session.cookie_path again – I mean the session_cookie_path setting in your config.inc.php.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Again Typo :(, I did not find session_cookie_path in the config.inc.php, we have only the session_cookie_name. Did you mean shall i set the session_cookie_path explicitly in the config.inc.php?

Even in the SessionManager.inc.php file, we have the following session parameters:

	// Configure PHP session parameters
	ini_set('session.use_trans_sid', 0);
	ini_set('session.save_handler', 'user');
	ini_set('session.serialize_handler', 'php');
	ini_set('session.use_cookies', 1);
	ini_set('session.name', Config::getVar('general', 'session_cookie_name')); // Cookie name
	ini_set('session.cookie_lifetime', 0);
	ini_set('session.cookie_path', $request->getBasePath() . '/');
	ini_set('session.cookie_domain', $request->getServerHost(null, false));
	ini_set('session.gc_probability', 1);
	ini_set('session.gc_maxlifetime', 60 * 60);
	ini_set('session.auto_start', 1);
	ini_set('session.cache_limiter', 'none');

So in the above, do we need to something for the session.cookie_path also?

Hi @gbcriado,

Look in config.TEMPLATE.inc.php for an example of how your session_cookie_path should be configured. If it’s not in your config.inc.php, perhaps that’s because you’re using a configuration file from an older release of OJS?

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

How are you?

Yes, i am using the old OJS 2.4.7-1 version, and i found the session_cookie_path in the OJS3 version, I will try out this option today and come back.

I tried seperately and i do not see the duplicate Sessions_Pkey issue but i am having a different issue as following, Could you please trace this out please:

(mysql): SELECT * FROM sessions WHERE session_id = ‘k7uhsgl1sudsp6c24j0o1d56q3’
(mysql): SELECT * FROM site
(mysql): SELECT v.* FROM versions v LEFT JOIN plugin_settings ps ON lower(v.product_class_name) = ps.plugin_name AND ps.setting_name = ‘enabled’ AND ((journal_id = 0) OR v.sitewide = 1) WHERE v.current = 1 AND (ps.setting_value = ‘1’ OR v.lazy_load <> 1)

Fatal error: Call to a member function getId() on null in C:\xampp\htdocs\ojs2\plugins\generic\customLocale\CustomLocalePlugin.inc.php on line 28
(mysql): UPDATE sessions SET user_id = NULL, ip_address = ‘127.0.0.1’, user_agent = ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36’, created = 1497460836, last_used = 1497461939, remember = 0, data = ‘’, domain = ‘ayush.in’ WHERE session_id = ‘k7uhsgl1sudsp6c24j0o1d56q3’

Hi @Umadhar,

Ah, unfortunately the session_cookie_path option will not work in OJS 2.4.7-1.

Can you clarify what version of OJS you’re using on this second installation?

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Yes, thats why i did not find the session_cookie_path in the OJS 2.4.7-1 .

For the 2nd installation also i am trying with the OJS 2.4.7-1 as i am afraid of upgrade how many issues i need to face and the problem is not solving hence not going for the upgrade.

What could be the issue for the following Fatal Error:
Fatal error: Call to a member function getId() on null in C:\xampp\htdocs\ojs2\plugins\generic\customLocale\CustomLocalePlugin.inc.php on line 28

Hi @Umadhar,

Your version of plugins/generic/customLocale/CustomLocalePlugin.inc.php seems to be different from the version included with OJS 2.4.7-1. Is it possible that you’re mixing files from different versions?

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

I did not mix anything except the public/ and files/ folder, and Just the DB. …

I did a check as following for ayushdhara.in:
-bash-4.2$ php tools/upgrade.php check
MIB search path: /var/www/tangenti/data/.snmp/mibs:/opt/alt/net-snmp/usr/share/snmp/mibs
Cannot find module (DCS3RMT-MIB): At line 1 in (none)
Cannot find module (DCS3FRU-MIB): At line 1 in (none)
Cannot find module (MIB-Dell-10892): At line 1 in (none)
Cannot find module (StorageManagement-MIB): At line 1 in (none)
Code version: 2.4.7.1
Database version: 2.4.7.1
Latest version: 3.0.2.0
A newer version is available:
tag: ojs-3_0_2-0
date: 2017-02-01
info: http://pkp.sfu.ca/ojs/
package: http://pkp.sfu.ca/ojs/download/ojs-3.0.2.tar.gz
patch: N/A

Another check on ijapr.in
-bash-4.2$ php tools/upgrade.php check
MIB search path: /var/www/tangenti/data/.snmp/mibs:/opt/alt/net-snmp/usr/share/snmp/mibs
Cannot find module (DCS3RMT-MIB): At line 1 in (none)
Cannot find module (DCS3FRU-MIB): At line 1 in (none)
Cannot find module (MIB-Dell-10892): At line 1 in (none)
Cannot find module (StorageManagement-MIB): At line 1 in (none)
Code version: 2.4.7.1
Database version: 2.4.7.1
Latest version: 3.0.2.0
A newer version is available:
tag: ojs-3_0_2-0
date: 2017-02-01
info: http://pkp.sfu.ca/ojs/
package: http://pkp.sfu.ca/ojs/download/ojs-3.0.2.tar.gz
patch: N/A

The new installation which i am doing version check as follows and this is on my local machine in xamp server:
php tools/upgrade.php check

(mysql): SET NAMES ‘utf8’


(mysql): SELECT setting_name, setting_value, setting_type FROM plugin_settings WHERE plugin_name = ‘announcementfeedplugin’ AND journal_id = ‘0’


(mysql): SELECT * FROM versions WHERE current = 1


(mysql): SELECT * FROM versions WHERE current = 1 AND product_type = ‘core’ AND product = ‘ojs2’


(mysql): SELECT setting_name, setting_value, setting_type FROM plugin_settings WHERE plugin_name = ‘backupplugin’ AND journal_id = ‘0’


(mysql): SELECT setting_name, setting_value, setting_type FROM plugin_settings WHERE plugin_name = ‘booksforreviewplugin’ AND journal_id = ‘0’


(mysql): SELECT setting_name, setting_value, setting_type FROM plugin_settings WHERE plugin_name = ‘browseplugin’ AND journal_id = ‘0’

PHP Fatal error: Call to a member function getId() on null in C:\xampp\htdocs\ojs2\plugins\generic\customLocale\CustomLocalePlugin.inc.php on line 26

Fatal error: Call to a member function getId() on null in C:\xampp\htdocs\ojs2\plugins\generic\customLocale\CustomLocalePlugin.inc.php on line 26

Not sure what the application is expecting here to be set.

Hi @Umadhar,

What is on line 26 in plugins\generic\customLocale\CustomLocalePlugin.inc.php?

Regards,
Alec Smecher
Public Knowledge Project Team