node.js - Sails doesn't start if hook use domain -


i create sails.js server can use third party code on hook initialization. want use domain catch error safely when error occurred, error catch correctly sails server doesn't start error :

error: error: hook `myhook` taking long load. make sure triggering `initialize()` callback, or else set `sails.config.plugins._hooktimeout higher value (currently 20000)     @ toolong [as _ontimeout] (/.../node_modules/sails/lib/app/private/loadhooks.js:92:21)     @ timer.listontimeout (timers.js:110:15) { [error: hook `plugins` taking long load. make sure triggering `initialize()` callback, or else set `sails.config.plugins._hooktimeout higher value (currently 20000)] code: 'e_hook_timeout' } 

here hook code :

module.exports = function (sails) {   return {     initialize  : function (next)     {       var scope = this;       sails.after(["hook:services:loaded", "hook:orm:loaded"], function ()       {           scope.loadplugins(next);       });     },     loadplugins : function (next)     {       var fs   = require("fs");       var path = require("path");        fs.readdir("plugins", function (err, list)       {          var domain = require('domain').create();         domain.on('error', function (err)           {             // handle error safely             sails.log.error(err);             sails.log.error(pluginname);           });         (var = 0; < list.length; i++)         {           var pluginname                           = list[i];           var plugin                               = require(__dirname + "/../../plugins/" + pluginname + "/" + pluginname + ".js");            sails.services.pluginservice[pluginname] = plugin;           domain.run(function ()           {             if (plugin.init)             {               plugin.init(function (err)               {                 if (err)                 {                   sails.log.error(err);                 }               });             }           });          }         if (next)         {           next();         }       });     }   } } 

i put breakpoint on next method , it's called correctly. sails doesn't see , make timeout. use node.js v0.12.2 , sails v0.11.0


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -