diff --git a/lib/agent.js b/lib/agent.js index f0228a690d..edae9a96df 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -26,10 +26,13 @@ class Agent extends EggApplication { // dump config after loaded, ensure all the dynamic modifications will be recorded const dumpStartTime = Date.now(); this.dumpConfig(); - this.coreLogger.info('[egg:core] dump config after load, %s', ms(Date.now() - dumpStartTime)); + this.coreLogger.info( + '[egg:core] dump config after load, %s', + ms(Date.now() - dumpStartTime) + ); // keep agent alive even it doesn't have any io tasks - setInterval(() => {}, 24 * 60 * 60 * 1000); + this.agentAliveHandler = setInterval(() => {}, 24 * 60 * 60 * 1000); this._uncaughtExceptionHandler = this._uncaughtExceptionHandler.bind(this); process.on('uncaughtException', this._uncaughtExceptionHandler); @@ -55,7 +58,13 @@ class Agent extends EggApplication { } _wrapMessenger() { - for (const methodName of [ 'broadcast', 'sendTo', 'sendToApp', 'sendToAgent', 'sendRandom' ]) { + for (const methodName of [ + 'broadcast', + 'sendTo', + 'sendToApp', + 'sendToAgent', + 'sendRandom', + ]) { wrapMethod(methodName, this.messenger, this.coreLogger); } @@ -63,8 +72,11 @@ class Agent extends EggApplication { const originMethod = messenger[methodName]; messenger[methodName] = function() { const stack = new Error().stack.split('\n').slice(1).join('\n'); - logger.warn('agent can\'t call %s before server started\n%s', - methodName, stack); + logger.warn( + "agent can't call %s before server started\n%s", + methodName, + stack + ); originMethod.apply(this, arguments); }; messenger.prependOnceListener('egg-ready', () => { @@ -75,9 +87,9 @@ class Agent extends EggApplication { close() { process.removeListener('uncaughtException', this._uncaughtExceptionHandler); + clearInterval(this.agentAliveHandler); return super.close(); } - } module.exports = Agent;