-
-
Notifications
You must be signed in to change notification settings - Fork 986
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
Option to save session before sending response #74
Comments
Can you verify if you still have the problem with version 1.7.5? A change was made to mostly address that referenced commit for the case you describe. |
i fear i still can see the issue, but commenting out this code Lines 216 to 229 in 5c503e7
|
can you explain what the "next request" is, exactly? |
first page is one email input and next button. The next page needs carry over of this email and more input fields. So next request is part of multipage form submission. |
ok. so by "next request is starting most of the time before the save is complete" you mean that you're able to click on the next button on that page before the session has been saved to the store, is that correct? if that is the case, the solution is a feature i have been meaning to add: an option to not send any response at all until the session has been saved to the store. this will make sure that you cannot click the button until the session is in the store. |
yeah exactly the issue. |
just in case you're not aware and feel like you have to wait on me, there is a work-around, which is to call app.post('/', function (req, res, next) {
// do stuff
req.session.email = email
req.session.save(function (err) {
if (err) return next(err)
res.render('page')
})
}) |
Excuse for late reply, but this is not really solving the issue. However I see session save happening twice. |
Oh, you have to set |
As per https://github.com/expressjs/session/blob/master/index.js#L297, if |
right, but |
I am afraid it's not working, what I am doing is wrapping |
After you asked about it, I tried it and it worked just fine. I can't really help you with the work-around if I have no idea what your code looks like :) Also, it may be useful to run under |
I tried |
@dougwilson Sorry for late reply again. here is the sample express app which highlights the issue. If you run this app and access http://localhost:3000/ and click on To highlight the issue, I have memory-store with get taking 50ms and set taking 80ms. This delay can be because of network latency or some other heavy async operation in store. |
@skoranga the example does not look like it is implementing the work-around I gave you at #74 (comment) , so of course it's not going to work. I already know it does not work :) But the issue is not easy to fix. You have to use that work-around I gave you above. |
sorry forgot to add the override. updated the sample-app. Now it's saving, but res.session.save is getting called twice as i mentioned in one of the above comment. if you insert this
|
yes. you need to set |
nevermind, i see you added |
OK, I see what the issue is. It looks like it has to do with the fact that the session is a new session when the page is loaded and it thinks the session hasn't been saved even after it is manually saved. |
Actually, the double-save would happen in all situations. The double-saving is definitely a bug, which I'll get fixed, now that I see it, thank you :) |
great. :) |
Hi @skoranga sorry for the delay. Can you |
thanks @dougwilson. it's working as expected with the latest code. So I will still be setting |
For now, yes. The |
I take that back: if you call |
Great. thanks for clarification. thanks for the fix. 👍 |
@skoranga sorry for the re-close :) I was just fixing the new code to not resave after you manually saved regardless of the |
Yes it works fine. :) |
I still have the same issue as @skoranga was having it. The I'm saving my sessions on files, I'm using the session-file-store. The problem I'm trying to solve is that when I call "res.redirect('/')", I noticed in the "./express-session/index.js", the
And then the
And it works, but, it is calling twice to the req.session.save which is a no no. I really need help. |
Looks like fix for #61 (901c8e0) is causing some wired race condition.
In my usecase
req.session.save
is calling also encrypting the data before storing. And usually it takes more little longer than non-encrypted version. Because of the async nature of session save the next request is starting most of the time before the save is complete. And this next request is fetching the old version of session.Is there any possibility to add some flag to control the async/sync session save or any other solution?
The text was updated successfully, but these errors were encountered: