express.io icon indicating copy to clipboard operation
express.io copied to clipboard

Chrome: On disconnect event the session data is not saved

Open DevDavido opened this issue 12 years ago • 1 comments

app.get('/home', function(req, res) {
    req.session.variable = 'value';
    req.session.save(function() {
        console.log(req.session);
    });
    res.send('<script src="/socket.io/socket.io.js"></script>\
              <script>var socket = io.connect();</script>\
              Home content');
});

app.io.route('disconnect', function(req) {
    console.log('-------------------------------');
    console.log(req.session);
    req.session.variable = '';
    req.session.save(function() {
        console.log(req.session);
        console.log('-------------------------------');
    });
});

Situation: I'm on the /home page and I reload the page. The output of the console in every(?) browser except Chrome after reload:

{ cookie:
   { path: '/',
     _expires: Mon May 19 2014 01:40:59 GMT+0200,
     originalMaxAge: 31536000000,
     httpOnly: true },
  variable: 'value' }
-------------------------------
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:40:59.399Z',
     httpOnly: true,
     path: '/' },
  variable: 'value',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:40:59.399Z',
     httpOnly: true,
     path: '/' },
  variable: '',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
-------------------------------
{ cookie:
   { path: '/',
     _expires: Mon May 19 2014 01:41:03 GMT+0200,
     originalMaxAge: 31536000000,
     httpOnly: true },
  variable: 'value' }

In Chrome:

{ cookie:
   { path: '/',
     _expires: Mon May 19 2014 00:43:37 GMT+0200,
     originalMaxAge: 31536000000,
     httpOnly: true },
  variable: 'value' }
{ cookie:
   { path: '/',
     _expires: Mon May 19 2014 00:43:37 GMT+0200,
     originalMaxAge: 31536000000,
     httpOnly: true },
  variable: 'value' }
-------------------------------
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:36:58.926Z',
     httpOnly: true,
     path: '/' },
  variable: 'value',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:36:58.926Z',
     httpOnly: true,
     path: '/' },
  variable: '',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
-------------------------------

Second reload:

{ cookie:
   { path: '/',
     _expires: Mon May 19 2014 00:43:37 GMT+0200,
     originalMaxAge: 31536000000,
     httpOnly: true },
  variable: 'value' }
-------------------------------
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:36:58.926Z',
     httpOnly: true,
     path: '/' },
  variable: '',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
{ cookie:
   { originalMaxAge: 31536000000,
     expires: '2014-05-18T23:36:58.926Z',
     httpOnly: true,
     path: '/' },
  variable: '',
  touch: [Function],
  resetMaxAge: [Function],
  save: [Function],
  reload: [Function],
  destroy: [Function],
  regenerate: [Function] }
-------------------------------

May this be a bug of Chrome and not express.io? It's also weird that the log order is different in Chrome than any other browser.

DevDavido avatar May 18 '13 23:05 DevDavido

I'm not quite sure what's going on in your example, but it's possible that in async scenarios that the execution order in different browsers will be different.

techpines avatar May 19 '13 22:05 techpines