Welcome Guest, Not a member yet? Register   Sign In
Session data lost every few seconds
#1

(This post was last modified: 11-29-2021, 11:58 PM by pJenkiss.)

Hello,
I spent my last week trying to google out any solution... still no answer. 

Shortly:
CI4 session data gets removed from time to time, and I don't know who does that. One of the ideas I found that it might be related with php garbage collector, but those forums were about CI3 and older, not sure whether might be relevant. 

Specific scenario:
I'm reviewing ci_session table. I login to my application - new record appears in ci_sessions. Go to other pages of the app - session works, ci_sessions record remains. Then I wait few seconds while not browsing the app (opened page does not have ajax requests) and refreshing ci_sessions table from time to time. And bam! - record from ci_sessions gets deleted. If I refresh my app page - I get redirected to login page. So the session data was removed while I wasn't browsing the app.
Session's removal time is random: sometimes I get logged out after 20 seconds, sometimes after a minute, sometimes I can't even login (I get redirected back to login page after successful login).

My code / settings:
I have filter setup for my app pages:
if(session()->get('admin')){
...
} else {
  log_message('error', 'This message is logged when I refresh the app after session gone');
}


Default settings :
sessionExpiration = 7200
sessionMatchIP = false (tried to set true - no effect)
sessionTimeToUpdate = 300
sessionRegenerateDestroy = false (tried to set true - no effect)

Interesting fact:
This is happening on my prod server only - I wasn't facing this issue locally nor on testing server.

Do you have any ideas what might cause the issue? Or at least where to look? I tries to change the ways how I initialize the session (nasty way, with helpers...) - it was working on my local machine all the time, but it wasn't on prod. So I assume it's something with prod settings, even though CI settings on prod are the same (except db, url settings, of course), but what? I'm not a server guy, so I have no clue what's happening there...
Reply
#2

Check the CI4 version and session table schema.

The database session had a bug and fixed in v4.1.5.
https://codeigniter.com/user_guide/insta...ble-change
Reply
#3

(11-30-2021, 12:02 AM)kenjis Wrote: Check the CI4 version and session table schema.

The database session had a bug and fixed in v4.1.5.
https://codeigniter.com/user_guide/insta...ble-change

Yes, I was using v4.1.4.... thank you very much! You saved the day / week Smile 

Initially I've updated just the code, but the issue still persisted. Then re-created ci_sessions table (as I noticed the only difference was CURRENT_TIMESTAMP and DEFAULT_GENERATED on `timestamp` column) - and it works now!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB