-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Losing Session Variable #6
Comments
From your issue I think session is cleared by the garbage collector. Are you sure whether cookie is valid when you loose your session? Default session lifetime for NodeSession is 5 minutes. ie, after this time cookie will get expire. Even though session will be present in the storage until the garbage collector hits the lottery. By default the chances of removing expired sessions from storage is twice per 100 requests(garbage collector is designed like this for performance reasons). Please see the garbage collector method of the file session driver here for more insight on this. |
(The problem might be solved [see below], but first...) @harishanchu I appreciate the insight. Yes the cookie's a good place to start, but the cookie has not expired. I'm keeping close track of it on the browser, and I set NodeSession However... Digging in the code I noticed NodeSession takes over the https://github.com/quorrajs/NodeSession/blob/master/index.js#L82 So, I started wondering if this was an issue with Ecstatic. I'm using it to deliver static files. Last evening I tried taking Ecstatic out of the picture. Here's my before code, in which
And my after code, where I exclude Ecstatic from the
I've been reloading, refreshing over and over yesterday and today and so far no problems. Whereas before I'd lose the session variable I set at least within, probably as you say, 100 requests, more often 10 or 20, or less. And here's the server code (in a nutshell):
|
I've been testing for the presence of the session var periodically throughout the day and have not lost it yet. It looks like moving Ecstatic outside the UPDATE: day two of testing, session variables remain. :) UPDATE # 2: four days later, session variable (initiated 4 days ago) remains! Have not lost it yet. |
Session variable goes missing. Cookie still valid. Session still valid. I'm using the file session storage. Looking at the session file, before and after missing, and the only thing different is the session variable is gone. I've copied the session file when the session variable is present and then restored the file after the session variable disappears and we're back up and running.
I can GET and POST any number of times, usually many times, sometimes only a few times, and the session variable remains, then the next round trip to the server and the session variable is gone immediately upon
startSession
.I've noticed in the session file
flash: { old: [], new: [] }
is present with the session variable, but goes missing along with the session variable.Looking at the server logs: on the last pass before it goes missing I can track the presence of the session variable all the way through the server processing, still there at the end of the procedure. Then on the next pass, immediately after
startSession
the session variable (andflash: { old: [], new: [] }
) is gone.Using this type of setup:
https://github.com/quorrajs/NodeSession/blob/master/examples/nodehttps.js
Setting the session variable, at login:
req.session.put('usertoken', usercredentialsobj.usertoken)
.Authenticating:
if ( true === req.session.has('usertoken') ) {
. Here is where I get directed to the login screen when the session variable is missing.If token exists, then comparing token to database:
db.usertokenvalid({usertoken:req.session.get('usertoken')}, function (err, usertokenobj) {
.The text was updated successfully, but these errors were encountered: