-
Notifications
You must be signed in to change notification settings - Fork 342
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 #135
Comments
The problem is that once I get in this state, |
I forgot to mention that we're using |
Something like this should really be handled upstream in the express-session project as we'd want a common API for any session store. I don't mind the idea though. Care to put up an issue there? |
Sure thing: Thanks Marc! |
The issue belongs here. Why can't the store retry on failures? |
In addition, the following seems like an issue with this module:
Why would |
@tciuro this sounds like an issue with |
agr... submitted early somehow, let's try this again @dougwilson the question of re-running the session though the middleware (the example you gave in the express-session project) is the sort of functionality I was getting at in my comment... or are you expecting libraries to continually retry and/or provide retry configuration until they get a session before going to the next middleware? Retry behavior seems something global to any network/disk session stores. |
right, that is our opinion. When we call the store to fetch a session, we only assume a reliable connection. Stores that do not have a reliable connection would be responsible for retrying, mainly because we have no way to know when to retry or when your session didn't exist, or when you had a fatal error and we shouldn't even bother retrying. |
@dougwilson thanks, that perspective is helpful, I'll take a peak and implement some sort of continual retry. This retry logic would be opt-in at this point as it may be breaking for some people but perhaps can be made default in a future release. |
For what is worth, the issue is only reproducible when using Node's cluster API. When I run it in single-process, I don't see a single mention of the The moment I run it with clustering on (one node per core), all hell breaks loose. |
We introduced a leak in our app. Once our server is under heavy load, we decide to shoot/relaunch the offending cluster worker that starts to misbehave. It's temporary until we find the culprit, but for now we keep this in place to allow the server to continue working. Each time a cluster worker bounces back, it gets inited with the same exact code path, where the session object is configured, a new I'm going to try something else: run the app in cluster mode without the worker management strategy activated. Let's see this issue appears again. I'll report back ASAP. |
Thanks for the update @tciuro (wish it was under better circumstances). What kind of logs to you get if you create a Redis client first and listen for its 'error' events? Anything telling? var client = require('redis').createClient(...)
client.on('error', console.log)
...
app.use(session({ store: new RedisStore({ client: client }) ... })) |
Glad to try getting to the bottom of this! :-) Just as I suspected, killing the cluster worker has negative implications. If I enable clustering but disable the "cycle worker" strategy, I never see this issue (though of course, the app starts leaking without an end in sight, other than bringing down the server). I've added the |
I have added support for the following Redis client events: |
A little more info. I have done two things: 1) add more logging in my app and 2) add more logging in This is what I see right before the first failure: the user has been authenticated, the session saved and the request returned successfully. The next request comes in and boom! The session cannot be retrieved. No error or event whatsoever has been displayed after the login succeeded and the session got saved:
Then, a new request comes along, only this time...:
Bingo! The last request was lucky enough to obtain the session after two tries (the original one + the retry). Weird, no? Any hunch about what could be causing this? |
@tciuro just out of curiosity, can you add a log within the function at https://github.com/tj/connect-redis/blob/master/lib/connect-redis.js#L115 and see if that gets called? Just add a log before the |
That is precisely what I did already. See step 2 in my previous comment (i.e. add more logging in |
I know, but you said you just added event listeners. I just wanted to add extra verification by adding a log directly within that anonymous function. |
OK, no worries. We're on the same page :-) |
@tciuro, you are on We really should be supporting express 3 and 4 in the latest releases and it doesn't seem like it should be hard to do. That would allow you to use the latest I've been playing around with retry and it looks more complicated than it should be, hopefully a solution will arise. |
Correct, I'm using I'll start updating the code by using |
Well, I have been testing on two Macs and so far I haven't seen the issue! I'm going to continue testing for the next couple days to see whether the issue has been truly solved. The middleware that I added thanks to @dougwilson still attempts to obtain the session, retrying a couple times and always succeeding. This is why I'm not yet 100% sure that the issue has been solved, but things do look way, way better. |
Good to hear :) Here's to not jinx it :) Feel free to update me on anything. I'm glad I asked what version of Express you were even on :) |
I learned that the updating frequently minimizes the amount of incompatibilities one can find. Because it's been so stable until now, we haven't had the need to bring anything up to date. Until now, that is. So thanks for the patience and guidance. One question: is there a reason why the built-in version of |
That's because the |
Is there a problem if I use |
The real question, I think, is what makes it not compatible with Express 3? Can @tciuro use the latest |
Yea. In fact, the latest Express 3 uses the latest |
I have been running 70+ integrations using Xcode Server on two different Macs since Saturday. I have yet to see the issue appear. I think the problem went away "simply" by upgrading (though it really wasn't just a drop-in replacement; I had to remove a series of deprecated calls as well as updating the middleware with the newer API). I would like to thank you both for the awesome help you've provided. I really appreciate it very much. @wavded, perhaps it would be a good idea to update the ReadMe for Express 3 users. I'd like to upgrade to Express 4 ASAP, but for other people not having the opportunity, it'd be great to have this sort of information. Again, thanks for everything. |
I went ahead and updated the readme. Good discussion. |
Hello,
Consider the snippet as shown in the documentation:
When
req.session
is not available, I ping Redis and it's available. The problem is that the request has already gone through the middleware. Would it be possible to include a function call in connect-redis to allow reloading the session manually? In other words, tell connect-redid to "try again". If we could obtain a session then, we could salvage the situation.The text was updated successfully, but these errors were encountered: