Uncaught PDOException in DB Managed Sessions?

62 views
Skip to first unread message

DS33511

unread,
Jan 11, 2018, 5:37:27 PM1/11/18
to Fat-Free Framework
Hi All,

I've been seeing a lot of the following 5XX errors in my application error log and I can't seem to find anything on this issue...

[Thu Jan 11 15:50:16.365568 2018] [:error] [pid 27537] [client XXX.XXX.XXX.XXX:44147] PHP Fatal error:  Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'c07fhlifdg6cmg96puu2hf0n2' for key 'PRIMARY' in /var/app/current/lib/db/sql.php:227\nStack trace:\n#0 /var/app/current/lib/db/sql.php(227): PDOStatement->execute()\n#1 /var/app/current/lib/db/sql/mapper.php(426): DB\\SQL->exec(Array, Array)\n#2 /var/app/current/lib/db/cursor.php(245): DB\\SQL\\Mapper->insert()\n#3 /var/app/current/lib/db/sql/session.php(95): DB\\Cursor->save()\n#4 [internal function]: DB\\SQL\\Session->write('c07fhk9cbdn4cmg...', '')\n#5 /var/app/current/lib/base.php(2046): session_commit()\n#6 [internal function]: Base->unload('/var/app/curren...')\n#7 {main}\n  thrown in /var/app/current/lib/db/sql.php on line 227

I'm running F3 version 3.6.1. Thinking about upgrading to the latest version, but I've looked at the latest changelog and see nothing related to this error.

It seems the session->write() method is invoking an insert rather than an update, and it's leading to a PK constraint violation on the sessions table. This does not happen all the time, only intermittently. I'm having a difficult time trying to reproduce it.

Has anyone else seen this before or can anyone shed some light on why this may be occurring?

Thanks very much!

ikkez

unread,
Jan 11, 2018, 9:01:39 PM1/11/18
to Fat-Free Framework
Well I once read about a similar issue here (https://groups.google.com/forum/#!searchin/f3-framework/session$20update|sort:date/f3-framework/CyO4777mScw/54tjbm7_BAAJ)
but it was about updating an expired session, which was caused by the garbage collector.. seems like this is not exactly your problem.

Usually the session handler will try to read the record from the database on initialization. And an insert or update is based on if the record was found or not.
I can recall there where some php7 updates for the session class in the latest version but nothing special.

Maybe it's some kind of race condition.. imagine 2 request coming at the same time from same client invoking a new session, but it wasn't fast enough to save the session in DB so that request 2 can successfully load it on time. You can try to set the 3rd parameter to false, then it wont try to install the DB table, if it's not existing yet.. that might speed it up a little:

new \DB\SQL\Session($DB, 'sessions', false);

but I'm really not sure if that will help here, sry.

Emmanuel Simond

unread,
Mar 15, 2018, 9:38:28 AM3/15/18
to Fat-Free Framework
hi . interesting

have you solved it_? 
Reply all
Reply to author
Forward
0 new messages