-
-
Notifications
You must be signed in to change notification settings - Fork 983
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
Recover a session manually when req.session is undefined #99
Comments
What session store are you using? That store needs to have an option for retrying if it fails. This module let's the store choose how it's going to handle connection failures. |
Anyway, to answer your question, there is 100% a way to retry: send the var sessionMiddleware = session( /* setup session here */ )
app.use(function (req, res, next) {
var tries = 3
function lookupSession(error) {
if (error) {
return next(error)
}
tries -= 1
if (req.session !== undefined) {
return next()
}
if (tries < 0) {
return next(new Error('oh no'))
}
sessionMiddleware(req, res, lookupSession)
}
lookupSession()
}) |
Hi Doug, I have added this middleware and when the issue occurs, I see the following message:
Why would it think I have configured a
Since the previous middleware creates the
The server just gets stuck and won't continue. Any idea what's going on? I'm using |
I wonder if the underlying issue is that the store gets released/lost/collected and a new |
Please follow the code above instead of the dual app.use you are trying to do. Otherwise, if you are having issues with that, post me something complete I can paste into a file unmodified and run |
Your issue is because the line
is completely invalid. |
I'm not sure what you mean. Typically,
You do:
So I can setup the
But I need to set the |
No. My middleware is already doing it. Replace your single app.use entirely with what I posted. It is your new session middleware app.use, basically. If you need me to write out an entire express app, let me know. |
No, Doug, you're already doing plenty by guiding me. Many thanks for that. My issue here is that the |
oohh. I just copied your code from the top:
so I thought you would know what it was. In that case, the first line of my code can be:
|
Aha! It works now. OK, thanks. After a while I end up getting:
So three attempts and nothing, we cannot get the |
Ok. I can't really say :) it does just like you asked: we're calling the store module 3 times. If the store module (which is outside my knowledge and this module) still doesn't return you a session after three tries, you really need to look into the store and it's code. All this module can do it just call it more (I.e. increase the retry number). According to the stack trace, though, we are not even calling the store for those three times because it told us to stoop calling it. Back over at the other issue, you can see the store has the ability to tell us to stop calling it until it tells us to start calling it again. It is a store module problem at that point, as we honor what the store tells us. |
By the way, what version of Express 3.x are you using? |
Express 3.4.8 |
Holy poop that is old. There is always the possibility that it's contributing to your issue. In that version of Express, |
I need to be very careful about updating modules, as it's already in production. Which version(s) should I update? I'd like to push that through QA first. I'd like to migrate to Express 4, but unfortunately it's a slow process for us. I'd like to take care of this issue in Express 3 first. Thanks for the help! |
So, I'm not specifically recommending to update it if you don't want to, but I am saying that you are not even using this module. If you want to use this module (without upgrading your version of express, so it's a bit less risky), you can change var express = require('express')
var app = express()
app.use(express.session({ ... }) to be var express = require('express')
var expressSession = require('express-session')
var app = express()
app.use(expressSession({ ... })) If there is a bug in that really old |
I'll definitely like to upgrade if it's compatible. Question: I see that the latest released version of |
All our modules are actually compatible with just a plain But for compatibility, if it doesn't work with Express 3.4.8, then it's a bug. |
I take this back, actually, because old version of this module may potentially not be compatible, at least versions prior to 1.0.4. |
Hello,
Consider the snippet as shown in the documentation:
When
req.session
is not available, I pingRedis
and it's available. The problem is that the request has already gone through the middleware, so there's no way to recover. Would it be possible to include a function call inconnect-redis
to allow reloading the session manually? In other words, tellconnect-redis
to "try again". If we could obtain a session then, we could salvage the situation.Once I get in this state,
connect-redis
never recovers. I get a!req.session
on every single request... butRedis
is working fine (I can access it without problems from terminal). Other than restarting the server (which sucks), is there a way to re-initializeconnect-redis
so that the next request can be properly initialized with a session?We're using
1.4.7
.The text was updated successfully, but these errors were encountered: