Skip to content
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

With DEBUG enabled, not seeing debug output #156

Closed
toddself opened this issue May 15, 2015 · 4 comments
Closed

With DEBUG enabled, not seeing debug output #156

toddself opened this issue May 15, 2015 · 4 comments
Assignees
Labels

Comments

@toddself
Copy link
Contributor

Running an app using express-session, but getting req.session is undefined when certain users try to access the server after a restart where we changed the session key. (FWIW this is the real bug we're trying to solve, and have eve implemented the suggestion from #99, but this issue isn't for that bug).

Right now I've got:

DEBUG=express-session:* node server.js

Right before I attach the session middleware:

if (process.env.DEBUG) {
    console.log('DEBUG is set to', process.env.DEBUG);
}
 var sessionMiddleware = session({
    store: sessionStore, // we are using connect-redis for now
    key: 'express_sid',
    secret: 'ABIGSECRET',
    resave: true,
    saveUninitialized: true,
    unset: 'destroy'
  });

  args.app.use(function (req, res, next) {
    var attempt = 0;

    function lookupSession(err) {
      if (err) {
        log.fatal('Error in session middleware', {err: err, req: req});
        return next(err);
      }

      ++attempt;

      if (req.session !== undefined) {
        return next();
      }

      if (attempt > maxAttempts) {
        log.fatal('unable to generate sessions, max attempts exhausted');
        return next(new Error('Unable to generate session'));
      }

      sessionMiddleware(req, res, lookupSession);
    }

    lookupSession();
  });

I see the following output when I start the server:
DEBUG is set to express-session:*

But I see no debug output whenever any of my clients hit the server. Any help is appreciated.

@dougwilson
Copy link
Contributor

It should be:

DEBUG=express-session node server.js

@dougwilson dougwilson self-assigned this May 15, 2015
@dougwilson
Copy link
Contributor

It's also important to note that your session store, connect-redis it seems, is what controls when the value of req.session will be undefined or not; this module is really just the management system for those stores. I'm just saying this because even if you start your server with the proper DEBUG=express-session node server.js, I'm not sure how much it's output will help.

@dougwilson
Copy link
Contributor

Actually, nevermind. You should see lots of store is disconnected in your output, which indicates that connect-redis is telling us not to ask it for sessions right now.

@toddself
Copy link
Contributor Author

Ah! That explains it. I thought you always needed to pass in a "component filter" for debug, or at least tell it not to filter the output at all.

Yeah, we're really scratching our heads with this one -- only SOME sessions are unable to do this, some work file. And we're using the same redis instance for our socket.io server, so we know it's there. (Although we are prepping to switch to the level one I wrote since we're a single node instance and don't really need redis here).

I'll give this a shot, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants