3

Sometimes when I reload the page, server is giving this error. When I restart the server it's working, but after a while it's giving same error again. I'm only storing user_id in session. Also I'm using Express.Io

Project/node_modules/express.io/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:46
          expires = 'string' == typeof sess.cookie.expires
                                                  ^
    TypeError: Cannot read property 'expires' of undefined
        at  Project/node_modules/express.io/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:46:47
        at process._tickCallback (node.js:419:13)

App.js

app.configure(function() {
    app.use(express.logger('dev'));
    app.use(express.cookieParser());
     app.use(express.session({
    secret: 'donkey',
    cookie: {
        maxAge: 12 * 3600000 // 12 hours
    }}));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
});

Express version : 3.4.8 Connect version : 2.12

../middleware/session/memory.js : http://pastie.org/9669160

Same problem : https://github.com/techpines/express.io/issues/6

Edit

I've tried to use req.session.touch() in every route, this time I' getting this error frequently(every time I restart app.js)

Project/node_modules/express.io/node_modules/express/node_modules/connect/lib/middleware/session/session.js:50
  this.cookie.maxAge = this.cookie.originalMaxAge;
                                  ^
    TypeError: Cannot read property 'originalMaxAge' of undefined
        at Session.resetMaxAge (Project/node_modules/express.io/node_modules/express/node_modules/connect/lib/middleware/session/session.js:50:35)
        at Session.touch 
Community
  • 1
  • 1
Lazy
  • 1,807
  • 4
  • 29
  • 49
  • Once I also got this error on aws staging, and then it vanished, then I moved my session store from mongo to redis, thinking mogo has some issue. Must know what happened. – Ashok Kumar Sahoo Oct 31 '14 at 11:29
  • Just an observation, **express.io** uses: `"express-session": "^1.2.1"`. Maybe you can force it to use a later version? – majidarif Oct 31 '14 at 11:36
  • Did you ever get this sorted out? Running Express 4.9.4 and `express-session` 1.9.1 and I am seeing the same TypeError, albeit in a slightly different context. Knowing how you fixed this would likely point me in the right direction. – Chris Krycho Nov 04 '14 at 19:06
  • I've created `session` collection in `mongoose` and whenever a user logins - registers, I'm creating a cookie and session document in mongo with his user id and session_id, using `res.cookie('sess_id', session_id)` and `new session(datas).save()` This is the most stable way. I don't suggest `req.session`, it's full of bugs(at least for me). I can explain it with more details if you want to make it like me. – Lazy Nov 04 '14 at 19:13

0 Answers0