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

mongojs stop processing further find requests after 2 mins #310

Open
thatisuday opened this issue Jun 3, 2016 · 5 comments
Open

mongojs stop processing further find requests after 2 mins #310

thatisuday opened this issue Jun 3, 2016 · 5 comments

Comments

@thatisuday
Copy link

Hi I am using mongodb version 3.0.7 and v2.4.0 of mongojs.

// Fetch from database
    db.products.find($query).sort(options.sort).skip(options.skip).limit(options.limit, function(err, docs){
        if(err){
            res.status(500).end();
        }
        else if(_.isEmpty(docs)){
            res.status(204).end();
        }
        else{
            res.json(docs);
        }
    });

Above is the simplest code for fetch some data from database. It works fine for 2 mins but after that, it just doesn't return the docs. Hence http request times out with status code 502 (Bad Gateway).

I am sure their might be some sort of memory leak in here but strangely other findOne queries are working fine even after this code breaks. Console doesn't show any error when this happens.

Any idea on this one guys?

@niqdev
Copy link

niqdev commented Jul 20, 2016

Hi, we have the same problem in production!
We have several microservices and only one endpoints under heavy loading after 10/30 mins goes down.
We suspect is due to a memory leak, we scale up but the problem remains.
I'm using hapi-mongojs wrapper.
The code is so simple that we don't know what change

findProducts(code) {
    return new Promise((resolve, reject) => {
      ...
      products.findOne({code}, {cs: 1, code: 1, _id: 0}, (error, document) => {
        if (error) {
          logger.log('error', error);
          reject(Boom.badData('Internal MongoDB error', error));
        } else {
          resolve({ code: code, relations: this.invokeXXX(document) });
        }
      });
    });

Any suggestions?
Thanks

@thatisuday
Copy link
Author

@niqdev I have moved to mongoose. It's due to mongojs's weak connection pool management, I guess.

@niqdev
Copy link

niqdev commented Jul 20, 2016

@thatisuday So, I think we will do the same or move directly to native in this case.
Thanks

@thatisuday
Copy link
Author

thatisuday commented Jul 20, 2016

@niqdev Please do that. mongoose is just super awesome. It will save you time and energy. You don't need to do separate validations. Also it provides SQL like joins. There are tons of good stuff. For overview, I have written a blog about it, please see this if you find it useful.

http://gitmeet.com/post/mongoose-js-part-1-in-a-nutshell
http://gitmeet.com/post/mongoose-part-2-in-depth-look

Native... Too much hardwork I guess.

@niqdev
Copy link

niqdev commented Jul 20, 2016

Thanks! I will have a look!

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

2 participants