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
fix: agent should exit on disconnect event whatever master kill with SIGKILL #27
Conversation
@fengmk2, thanks for your PR! By analyzing the history of the files in this pull request, we identified @dead-horse, @popomore and @ngot to be potential reviewers. |
我得加测试用例。 |
lib/agent_worker.js
Outdated
@@ -23,12 +23,22 @@ agent.ready(() => { | |||
agent.once('error', startErrorHandler); | |||
function startErrorHandler(err) { | |||
consoleLogger.error(err); | |||
consoleLogger.error('[agent_worker] Agent Worker start error, exiting now!'); | |||
consoleLogger.error('[agent_worker] start error, exiting with code:1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
后空格,下面几个也是
lib/master.js
Outdated
|
||
function receiveSig(sig) { | ||
debug('receive signal %s, exit with code 0, pid %s', sig, process.pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改为 arrow , 上面省去 bind?
lib/agent_worker.js
Outdated
|
||
process.once('disconnect', () => { | ||
consoleLogger.info('[agent_worker] got disconnect event on child_process fork mode, exiting with code:0'); | ||
process.exit(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
讨论是 exit 1 的?
Codecov Report
@@ Coverage Diff @@
## master #27 +/- ##
==========================================
- Coverage 96.59% 95.19% -1.41%
==========================================
Files 7 7
Lines 294 333 +39
==========================================
+ Hits 284 317 +33
- Misses 10 16 +6
Continue to review full report at Codecov.
|
加了一个 io loop 等 SIGTERM 事件发生,避免误判 |
这个测试怎么没有触发 appveyor |
// kill(15) default | ||
process.once('SIGTERM', this.onSignal.bind(this, 'SIGTERM')); | ||
|
||
process.once('exit', this.onExit.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atian25 改了
@@ -385,6 +419,17 @@ class Master extends EventEmitter { | |||
} | |||
require('cluster-reload')(this.options.workers); | |||
} | |||
|
|||
close() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实现优雅退出
process.once('exit', code => { | ||
// istanbul can't cover here | ||
// https://github.com/gotwarlost/istanbul/issues/567 | ||
this.killAgentWorker(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原来之前是通过这里来 kill agent 的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对,写得比较挫
1.6.4 |
process.once('SIGQUIT', receiveSig.bind(null, 'SIGQUIT')); | ||
// kill(15) default | ||
process.once('SIGTERM', receiveSig.bind(null, 'SIGTERM')); | ||
onExit(code) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit 不需要 close?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要了,进程马上就退出
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onSignal => close => onExit(code)
这个 fix 也证明,通过 child_process fork 出来的子进程,如果需要实现父进程挂了子进程也跟着挂,必须在子进程里面也加上相应的处理,才能实现,没办法只通过父进程来实现。 |
哦,除非再起一个观察者进程,发现父进程挂了,然后去强制杀掉未退出的子进程,然后自杀。 |
closes eggjs/egg#960
Checklist
npm test
passesAffected core subsystem(s)
Description of change