Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef97f25

Browse files
committed
fix bug in reload, only the first process in dielist will be kill
1 parent 13c0b70 commit ef97f25

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lib/child.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ exports.create = function (argv, options) {
7272
*/
7373
this.pstatus = {};
7474

75+
/**
76+
* @ 正常进程数
77+
*/
78+
this.okcount = 0;
79+
7580
/**
7681
* @ 即将消亡的进程列表
7782
*/
@@ -122,6 +127,8 @@ exports.create = function (argv, options) {
122127
delete workers[pid];
123128
delete _self.pstatus[pid];
124129
delete _self.dielist[pid];
130+
131+
_self.okcount = Math.max(0, _self.okcount - 1);
125132
_self.emit('exit', pid, code, signal);
126133

127134
if (!_self.running) {
@@ -163,10 +170,12 @@ exports.create = function (argv, options) {
163170
} catch (e) {
164171
}
165172
});
166-
for (var i in _self.dielist) {
167-
if (workers[i]) {
168-
workers[i].kill('SIGTERM');
169-
break;
173+
_self.okcount++;
174+
if (_self.okcount >= _options.children / 2) {
175+
for (var i in _self.dielist) {
176+
if (workers[i]) {
177+
workers[i].kill('SIGTERM');
178+
}
170179
}
171180
}
172181
} else if ('function' === (typeof MessageHandle[msg.type])) {
@@ -188,6 +197,7 @@ exports.create = function (argv, options) {
188197
n++;
189198
}
190199
});
200+
_self.okcount = n;
191201

192202
while (n < _options.children) {
193203
_self._fork();
@@ -200,6 +210,7 @@ exports.create = function (argv, options) {
200210
Child.prototype.stop = function (signal) {
201211
var _self = this;
202212
_self.running = 0;
213+
_self.okcount = 0;
203214

204215
Object.keys(handles).forEach(function (i) {
205216
handles[i].close();
@@ -221,6 +232,7 @@ exports.create = function (argv, options) {
221232
/* {{{ public prototype reload() */
222233
Child.prototype.reload = function () {
223234
var _self = this;
235+
_self.okcount = 0;
224236
Object.keys(workers).forEach(function (i) {
225237
_self.dielist[i] = true;
226238
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pm",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"author": "Aleafs Zhang ([email protected])",
55
"contributors": [
66
{"name": "fengmk2", "email": "[email protected]", "web": "http://fengmk2.github.com"}

0 commit comments

Comments
 (0)