Skip to content
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

express-session sometimes saves empty sessions (very rarely) #463

Open
bash-tp opened this issue Jan 10, 2023 · 0 comments
Open

express-session sometimes saves empty sessions (very rarely) #463

bash-tp opened this issue Jan 10, 2023 · 0 comments

Comments

@bash-tp
Copy link

bash-tp commented Jan 10, 2023

This is a duplicate of expressjs/session#925 because Doug suggested the problem is more likely to be at the connect-mongo layer!


We're using express-session 1.17.2 with connect-mongo 4.6.0. Our app creates thousands of new sessions every day and we rarely have any issues. But sometimes I'll start getting this alert:

Error: TypeError: Cannot read property 'expires' of undefined
    at MongoStore.Store.createSession (node_modules/express-session/session/store.js:87:29)
    at inflate (node_modules/express-session/index.js:372:13)
    at node_modules/express-session/index.js:499:11
    at node_modules/connect-mongo/build/main/lib/MongoStore.js:222:17
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

When I get the session id and look in mongo, the session field contains the string {}. Somehow it saves an empty json object with no cookie key. I need to manually delete the session so the user gets a new one and then it's resolved.

This happens maybe once a month or so. It's such a tiny fraction of all sessions, but it's still frustrating. It's got to be a race condition somewhere but I haven't been able to find anything obvious.

Has behavior like this been reported before? If not, is it possible to add error checking to avoid returning an invalid session that's missing its session.cookie?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant