I\'m having a problem with sessions, where sometimes the session variable I just set is undefined on the next page request. I typically have to go through the flow
In Connect's session, any handler can set req.session.anything to any value, and Connect will store the value when your handler calls end(). This is dangerous if there are multiple requests in flight at the same time; when they finish, one session value will clobber the other. This is the consequence of having such a simple session API (or see the session source directly), which has no support to atomically get-and-set session properties.
The workaround is to try to give the session middleware as few of the requests as necessary. Here are some tips:
express.static handler above the session middleware.req.session by saying express.session.ignore.push('/individual/path').req.session = null; before calling res.end();. Then it won't be re-saved.If only one request does a read-modify-write to the session at a time, clobbering will be less likely. I hope that in the future, Connect will have a more precise session middleware, but of course the API will be more complicated than what we have now.