4

I have made a nodejs application using sails.js. It's working perfectly in my localhost. The problem appears in production when I try to publish it in the server(modulus). You can take a look the error below.

Error: The hook `pubsub` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set `sails.config.pubsub._hookTimeout to a higher value (currently 20000)
    at tooLong [as _onTimeout] (/mnt/data/1/ApiDevConf-master/node_modules/sails/lib/app/private/loadHooks.js:92:21)
    at Timer.listOnTimeout (timers.js:110:15) { [Error: The hook `pubsub` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set `sails.config.pubsub._hookTimeout to a higher value (currently 20000)] code: 'E_HOOK_TIMEOUT' }

I have tried to figure out how to solve the problem but nothing works. I was trying somethink like this here.

Also I have properly set the NODE_ENV = production

Thanks for your time.

Community
  • 1
  • 1
gon250
  • 3,405
  • 6
  • 44
  • 75

1 Answers1

8

It sounds like this could be one of two issues.

1.) You need to set your migrate setting in config/model.js to something besides alter. You should have migrate: 'safe' on in production mode. This should happen automatically if the NODE_ENV variable is set to production.

The reason it times out is every time you start the server Sails will try and migrate your existing data to the current schema. Obviously don't want this in production.

2.) You have a lot of files to load and Modulus is slow to read them from it's virtual disk. This is a bigger issue because it will take a very long time for your server to start each time you need to restart it. You can bump the global timeout limit and that should give you more time. To do that add the following to your config/env/production.js file:

module.exports = {
  hookTimeout: 40000
}
particlebanana
  • 2,416
  • 21
  • 22
  • hey @particlebanana I have added the ``migrate: 'safe'``and nothing. Also I have tried the second option and doesn't work.. :s would help if I share to you my code on github?¿ (http://devconf-45442.onmodulus.net/) – gon250 Apr 16 '15 at 18:18
  • Yeah if you have a github link that would be great – particlebanana Apr 16 '15 at 22:05
  • Probably is a stupid thing.. but I can't find what it is. https://github.com/gon250/ApiDevConf @particlebanana thanks! – gon250 Apr 16 '15 at 22:09
  • @gon250 in that project you still have `migrate: 'alter'` on. Can you set that `migrate: 'safe'` and can you try moving the hookTimeout to `config/env/development.js` to see if that works. Could be the env isn't actually getting set. Also maybe try increasing it some more. Everything looks right. – particlebanana Apr 17 '15 at 15:06
  • Well..I did the changes..(https://github.com/gon250/ApiDevConf) but doesn't work.. I'm thinking to use a different server. but it's weird because in local it's working perfect. @particlebanana – gon250 Apr 17 '15 at 16:06
  • Not sure whats up then, I cloned your project and it deployed fine to modulus for me. – particlebanana Apr 17 '15 at 23:07
  • I got it!! :) I have fixed the problem. What I did is publish by the terminal not by the website. – gon250 Apr 18 '15 at 11:05