Why wouldn't a waterline callback happen to be triggered?

173 views Asked by At

I'm using Sails built in models and it's ORM to perform MongoDB queries and operations. The problem I got is that, for some query methods,it's callback is never being called. The DB operation gets done, but callback won't come up. Following code snippet is model querying part of a controller method for an API, that's why I'm using a response object.

  LineUp.update({ id: request.param('id') },
                { players: [], budgetLeft: 60000000 }).
  exec(function (err, lineup) {
    console.log("Should happen");
    return err ? response.send(500) : response.json(lineup);
  });

So, I've read Sails docs and it seems I'm actually doing as it's supposed to, but it wont' work.

By won't work, I mean callback ist's not being executed, I can never see Should happen, and then any response is sent back to client, a 502 timeout is reached at client side.

Edit

I could notice and found out this is a sails-mongo issue.

I first had "sails-mongo": "^0.10.6" as dependency in my package.json and got mongodb as dev dependency in last version for this former.

I tested whole code with postman and I couldn't notice any issue. After a npm install run I started to notice it failing, then I found out it was the callback issue.

After an update of sails-mongo to ^0.11.2 I could see how it simply worked back gain. However I could see other model queries a moment when it was not working.

At staging server (and sadly not working) I had sails-mongo ^0.10.8 and 2.0.33 modules when it got failing. I updated both to last versions and in particular sails-mongo to 0.11.x branch.

I really need not only to solve this but know the reason. I've tried to replicate the error but now it's working while it didn't for two days.

Edit 2 (syntax error or bug?)

I can't replicate the error by trying distinct module versions. But, also strange, I've determinaed which code style is not working (with no callback happening).

No callback being executed, leads to timeout:

  LineUp.update({ id: request.param('id') }, { players: [], budgetLeft: 60000000 })
  .exec(function(err, lineup) { return err ? response.send(500) : response.json(lineup)});

Against, a simple checkout to this version below which will make it work:

Works normally, callback executed and then any timeout but normal server response:

  LineUp.update({id: request.param('id')}, { players: [], budgetLeft: 60000000 }).
    exec(function (err, lineups) {
      console.log("Happens");
      console.log(lineups);
      return err ? response.send(500) : response.json(lineups);
    });

But uh, aren't they the same!?

Possible bug. I submitted this as an issue on github

Edit 3 Found when it's failing.

This will fail when it actually does a modification.

So anytime a match is made, even though modification at database is performed, callaback is not being triggered. If not match is found for updating, callback will execute.

I've tested this with out mongodb module at package.json with 0.11.2, 0.10.6 and 0.10.8 versions of sails-mongo and find the same issue.

0

There are 0 answers