Req.session is often undefined in the route (connect-redis is used as storage)

The problem is this: in a deployed nodejitsu application, often (not always!), When I redirect from the browser (clicks aa href = "/ logout") to the / logout route, I get a request. undefined session inside this route.

app.get('/logout', function(req, res){
   log.debug("session", req.session); //undefined
});

Requests go through the following stack of "middleware":

var store = new db.store({client: db.client}); // no problems here, redis monitor confirms
app.configure(function(){
    [...]
    app.use(express.cookieParser("XXXpassXXX"));
    app.use(express.bodyParser());
    app.use(express.session({
        secret: "XXXpassXXX",
        store: store
    }));
    app.use(function(req, res, next) {
        var fullURL = req.protocol + "://" + req.get('host') + req.url;
        if (fullURL.indexOf("logout") != -1 || fullURL[fullURL.length-1] == "/") {
            log.debug(fullURL);
            log.debug("sesiune", JSON.stringify(req.session)); // undefined for the "/logout" route !!!
            log.debug("cookies", JSON.stringify(req.cookies));
        }
        next();
    });
    app.use(passport.session());
    app.use(app.router);
});

I checked the browser and sent the cookies to the server and to my "logger" middleware, I see that fullURL is installed correctly.

Also, the last request made by the redis application for the application before the failure is to get "sess: xxx" in the correct session identifier (which is stored correctly in the database).

, express.session() connect-redis, () , req.session undefined, , redis "get" ?

PS: redis .

+3
1

, , , , . , .

, , , - . :

node_modules/express/node_modules/connect/middleware/session.js

, function session(options){; . 25 return function session(req, res, next){; . , , session ​​(-, next()). , . debug() , . DEBUG express:*. Nodejitsu, , .

Nodejitsu, : session , ( - ). Nodejitsu , , .

+3

All Articles