Option to save session before sending response
See original GitHub issueLooks like fix for https://github.com/expressjs/session/issues/61 (https://github.com/expressjs/session/commit/901c8e062c8789d3963ebe175a75d25d3c229245) 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?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:30 (16 by maintainers)
Top Results From Across the Web
NodeJs express-session don´t save the session - Stack Overflow
I´ve rewrite the code like this: app.post('/login', function(req, res) { console.log("Before: "); console.log(sess); sess = req.session; ...
Read more >Express session middleware
Create a session middleware with the given options . Note Session data is not saved in the cookie itself, just the session ID....
Read more >Session Management in Node.js using ExpressJS and ...
This tutorial will help the reader develop a session based authentication system and go over how to manage sessions using Express.js and ...
Read more >Manage the Skill Session and Session Attributes | Alexa Skills ...
Save data during the session. To retain data during the session, use session attributes. Create a map of key/value pairs with the data...
Read more >How to Manage Session using Node.js and Express
If you want to send Anything to Nodejs server, you can do it using GET or POST HTTP method. Now as per your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
req.session.save
yourself and respond within that callback. for exampleI still have the same issue as @skoranga was having it. The
res.session.save()
is saving twice. I’m using “express”: “4.16.2”, “express-session”: “1.15.6”. I really need help!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
res.end()
gets ran and inside of that, the following gets ranAnd then the
req.session.save
runs asynchronously which then the redirection to\
starts happening and the session gets loaded BUT thereq.session.save
hasn’t finished saving the session in the file which then causes to load the old or previous state of the session. I used the suggested workaround (see below) of callingreq.session.save
before the redirectingAnd it works, but, it is calling twice to the req.session.save which is a no no. I really need help.