question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sessions collection is too big

See original GitHub issue

I installed connect-mongo a few days ago now to store my express-sessions in my DB. Today I checked my sessions collection and found out that there were more than 200,000 documents in there! I tried deleting my collection and waiting 60 seconds, and there were already 200 documents in there.

Why are documents being resaved even though I have resave set to false? It seems as if documents are being saved endlessly…

Here is my current configuration:

app.use(session({
    secret: config.secret,
    resave: false,
    saveUninitialized: false,
    unset: 'destroy',
    store: new MongoStore({
        mongooseConnection: mongoose.connection,
        touchAfter: 3600, //Restore once every hour
        autoRemove: 'interval',
        autoRemoveInterval: 60 //Remove after one hour
    })
}));

At most I would only have around 3 users using my app at the moment.

I contacted connect-mongo and they stated that it would have to be an issue with express-session.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dougwilsoncommented, Jun 28, 2016

@romeboards , you also need ton use saveUninitialized: false, not saveUninitialized: true in your code, otherwise everything that hits your server, event assets, will keep creating a new session. If you are using true, then what you are experiencing is expected…

0reactions
joewagnercommented, Jun 29, 2016

@zilions From your first post you mention that you’ve got 200 documents after 60 seconds. Thats about 3 requests a second. That seems like quite a few for only 3 users. Do you log all requests? If you are getting that many requests, then somewhere in your code you are probably touching the session for each request even though you aren’t intending to use it. Based on previous issues I’ve seen, this is potentially happening in the jwt script you mention. But, I have no way to know that without grepping around your code. If you aren’t getting 3 requests/second, then something other than express-session is likely the culprit.
Either way, I wouldn’t think the indexes you have set on the collection have anything to do with the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Sessions collection too big in a MEAN app. Is it okay to ...
I'm making changes to an old MEAN app and just found out that the sessions collection is huge (more than 38 million records)....
Read more >
huge number of updates on system.sessions collection
When a user creates a session on a mongod or mongos instance, the record of the session initially exists only in-memory on the...
Read more >
How should I handle session files that become too numerous?
@davidalger - PHP's own garbage collection operates via cron. It simply find s all files older than sess.gc_maxlifetime and removes them. Deleting sessions...
Read more >
Large Session Size Causing Sitecore Redis Timeouts, Identify ...
Identifying a data size issue is quite simple once you have the prerequisites in place. Specifically, you need access to a Redis CLI...
Read more >
MongoDB Limits and Thresholds
This document provides a collection of hard and soft limitations of the MongoDB ... option to allow for the migration of ranges that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found