From 5c5d45b016495d8d8877b165aa537de3961fa5fc Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 17:08:36 +0800 Subject: [PATCH 01/11] feat: support win32 it should stop with --port if start cluster with custom port number --- lib/cmd/stop.js | 11 ++--- lib/helper.js | 50 ++++++++++++++++++++- test/start.test.js | 12 ++--- test/stop.test.js | 106 +++++++++++++++++++++++++++------------------ test/utils.js | 5 ++- 5 files changed, 124 insertions(+), 60 deletions(-) diff --git a/lib/cmd/stop.js b/lib/cmd/stop.js index 250014e..ef062b1 100644 --- a/lib/cmd/stop.js +++ b/lib/cmd/stop.js @@ -17,13 +17,8 @@ class StopCommand extends Command { } * run(context) { - /* istanbul ignore next */ - if (process.platform === 'win32') { - this.logger.warn('Windows is not supported, try to kill master process which command contains `start-cluster` or `--type=egg-server` yourself, good luck.'); - process.exit(0); - } - const { argv } = context; + const port = argv.port || (process.env && process.env.PORT); // egg-script stop // egg-script stop ./server @@ -38,7 +33,7 @@ class StopCommand extends Command { let processList = yield this.helper.findNodeProcess(item => { const cmd = item.cmd; return cmd.includes(this.serverBin) && cmd.includes(`"baseDir":"${baseDir}"`); - }); + }, port); let pids = processList.map(x => x.pid); if (pids.length) { @@ -56,7 +51,7 @@ class StopCommand extends Command { processList = yield this.helper.findNodeProcess(item => { const cmd = item.cmd; return cmd.includes(`"baseDir":"${baseDir}"`) && (cmd.includes('app_worker.js') || cmd.includes('agent_worker.js')); - }); + }, port); pids = processList.map(x => x.pid); if (pids.length) { diff --git a/lib/helper.js b/lib/helper.js index 881d869..6f3c477 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -3,7 +3,11 @@ const runScript = require('runscript'); const REGEX = /^\s*(\d+)\s+(.*)/; -exports.findNodeProcess = function* (filterFn) { +exports.findNodeProcess = function* (filterFn, port) { + if (process.platform === 'win32') { + return yield findNodeProcessWin(port); + } + const command = 'ps -eo "pid,command"'; const stdio = yield runScript(command, { stdio: 'pipe' }); const processList = stdio.stdout.toString().split('\n') @@ -21,12 +25,54 @@ exports.findNodeProcess = function* (filterFn) { return arr; }, []); return processList; + }; +function* findNodeProcessWin(port) { + port = +port; + if (!Number.isSafeInteger(port)) { + return []; + } + const command = `netstat -aon|findstr ":${port}"`; + let stdio; + + try { + stdio = yield runScript(command, { stdio: 'pipe' }); + } catch (ex) { + return []; + } + const processList = stdio.stdout.toString().split('\n') + .reduce((arr, line) => { + if (line) { + // [ '', 'TCP', '0.0.0.0:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + // [ '', 'TCP', '[::]:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + const lineArr = line.split(/\s+/); + + if (!lineArr[0] && lineArr[1] === 'TCP' && lineArr[2] && lineArr[5]) { + const pid = lineArr[5]; + const ipArr = lineArr[2].split(':'); + + if (!Number.isSafeInteger(+pid)) { + return arr; + } + + if (ipArr && ipArr.length >= 2) { + if (+ipArr[ipArr.length - 1] === port) { // ipv4/v6 + arr.push({ pid, cmd: '' }); + } + } + } + } + return arr; + }, []); + + return processList; +} + exports.kill = function(pids, signal) { pids.forEach(pid => { try { - process.kill(pid, signal); + process.kill(pid, 0) && process.kill(pid, signal); } catch (err) { /* istanbul ignore next */ if (err.code !== 'ESRCH') { throw err; diff --git a/test/start.test.js b/test/start.test.js index f00ce80..e940bf4 100644 --- a/test/start.test.js +++ b/test/start.test.js @@ -175,7 +175,7 @@ describe('test/start.test.js', () => { after(function* () { app.proc.kill('SIGTERM'); - yield utils.cleanup(fixturePath); + yield utils.cleanup(fixturePath, 7002); }); it('should start', function* () { @@ -201,7 +201,7 @@ describe('test/start.test.js', () => { after(function* () { app.proc.kill('SIGTERM'); - yield utils.cleanup(fixturePath); + yield utils.cleanup(fixturePath, 7002); }); it('should start', function* () { @@ -271,7 +271,8 @@ describe('test/start.test.js', () => { let result = yield httpclient.request('http://127.0.0.1:7001/env'); assert(result.data.toString() === 'pre, true'); result = yield httpclient.request('http://127.0.0.1:7001/path'); - assert(result.data.toString().match(new RegExp(`^${fixturePath}/node_modules/.bin${path.delimiter}`))); + const p = path.normalize(`${fixturePath}/node_modules/.bin${path.delimiter}`).replace(/\\/g, '\\\\'); + assert(result.data.toString().match(new RegExp(`^${p}`))); }); }); @@ -318,7 +319,7 @@ describe('test/start.test.js', () => { after(function* () { app.proc.kill('SIGTERM'); - yield utils.cleanup(fixturePath); + yield utils.cleanup(fixturePath, 8000); }); it('should start', function* () { @@ -351,6 +352,7 @@ describe('test/start.test.js', () => { .debug() .end(); yield utils.cleanup(cwd); + yield utils.cleanup(cwd, 7002); }); it('should start custom-framework', function* () { @@ -412,7 +414,7 @@ describe('test/start.test.js', () => { mm(process.env, 'WAIT_TIME', 5000); mm(process.env, 'ERROR', 'error message'); - const stderr = path.join(homePath, 'logs/master-stderr.log'); + const stderr = path.join(homePath, 'logs/master-stderr.log').replace(/\\/g, '\\\\'); yield coffee.fork(eggBin, [ 'start', '--daemon', '--workers=1' ], { cwd }) // .debug() diff --git a/test/stop.test.js b/test/stop.test.js index bb79773..af02c5d 100644 --- a/test/stop.test.js +++ b/test/stop.test.js @@ -17,6 +17,7 @@ describe('test/stop.test.js', () => { const homePath = path.join(__dirname, 'fixtures/home'); const logDir = path.join(homePath, 'logs'); const waitTime = '10s'; + const fixturePathR = path.normalize(fixturePath).replace(/\\/g, '\\\\'); // for win32 before(function* () { yield mkdirp(homePath); @@ -58,15 +59,18 @@ describe('test/stop.test.js', () => { // yield killer.end(); yield sleep(waitTime); + + if (process.platform !== 'win32') { // make sure is kill not auto exist - assert(!app.stdout.includes('exist by env')); - - assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); - assert(app.stdout.includes('[master] exit with code:0')); - assert(app.stdout.includes('[app_worker] exit with code:0')); - // assert(app.stdout.includes('[agent_worker] exit with code:0')); - assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); - assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + assert(!app.stdout.includes('exist by env')); + + assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); + assert(app.stdout.includes('[master] exit with code:0')); + assert(app.stdout.includes('[app_worker] exit with code:0')); + // assert(app.stdout.includes('[agent_worker] exit with code:0')); + assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); + assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + } }); }); @@ -76,18 +80,20 @@ describe('test/stop.test.js', () => { killer.debug(); killer.expect('code', 0); - // yield killer.end(); - yield sleep(waitTime); + if (process.platform !== 'win32') { + // yield killer.end(); + yield sleep(waitTime); - // make sure is kill not auto exist - assert(!app.stdout.includes('exist by env')); - - assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); - assert(app.stdout.includes('[master] exit with code:0')); - assert(app.stdout.includes('[app_worker] exit with code:0')); - // assert(app.stdout.includes('[agent_worker] exit with code:0')); - assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); - assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + // make sure is kill not auto exist + assert(!app.stdout.includes('exist by env')); + + assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); + assert(app.stdout.includes('[master] exit with code:0')); + assert(app.stdout.includes('[app_worker] exit with code:0')); + // assert(app.stdout.includes('[agent_worker] exit with code:0')); + assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); + assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + } }); }); @@ -97,18 +103,20 @@ describe('test/stop.test.js', () => { killer.debug(); killer.expect('code', 0); - // yield killer.end(); - yield sleep(waitTime); + if (process.platform !== 'win32') { + // yield killer.end(); + yield sleep(waitTime); - // make sure is kill not auto exist - assert(!app.stdout.includes('exist by env')); - - assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); - assert(app.stdout.includes('[master] exit with code:0')); - assert(app.stdout.includes('[app_worker] exit with code:0')); - // assert(app.stdout.includes('[agent_worker] exit with code:0')); - assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); - assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + // make sure is kill not auto exist + assert(!app.stdout.includes('exist by env')); + + assert(app.stdout.includes('[master] receive signal SIGTERM, closing')); + assert(app.stdout.includes('[master] exit with code:0')); + assert(app.stdout.includes('[app_worker] exit with code:0')); + // assert(app.stdout.includes('[agent_worker] exit with code:0')); + assert(killer.stdout.includes(`[egg-scripts] stopping egg application at ${fixturePath}`)); + assert(killer.stdout.match(/got master pid \["\d+\"\]/i)); + } }); }); }); @@ -130,21 +138,33 @@ describe('test/stop.test.js', () => { }); it('should stop', function* () { - yield coffee.fork(eggBin, [ 'stop', fixturePath ]) - .debug() - .expect('stdout', new RegExp(`\\[egg-scripts] stopping egg application at ${fixturePath}`)) - .expect('stdout', /got master pid \["\d+\"\]/i) - .expect('code', 0) - .end(); + if (process.platform !== 'win32') { + yield coffee.fork(eggBin, [ 'stop', fixturePath ]) + .debug() + .expect('stdout', new RegExp(`\\[egg-scripts] stopping egg application at ${fixturePath}`)) + .expect('stdout', /got master pid \["\d+\"\]/i) + .expect('code', 0) + .end(); - yield sleep(waitTime); + yield sleep(waitTime); + + // master log + const stdout = yield fs.readFile(path.join(logDir, 'master-stdout.log'), 'utf-8'); - // master log - const stdout = yield fs.readFile(path.join(logDir, 'master-stdout.log'), 'utf-8'); + assert(stdout.includes('[master] receive signal SIGTERM, closing')); + assert(stdout.includes('[master] exit with code:0')); + assert(stdout.includes('[app_worker] exit with code:0')); + } else { + yield coffee.fork(eggBin, [ 'stop', fixturePath ]) + .debug() + .expect('stdout', new RegExp(`\\[egg-scripts] stopping egg application at ${fixturePathR}`)) + .expect('stdout', /(got master pid \["\d+\"\])|(\[egg-scripts\] stopped)/i) + .expect('code', 0) + .end(); + + yield sleep(waitTime); - assert(stdout.includes('[master] receive signal SIGTERM, closing')); - assert(stdout.includes('[master] exit with code:0')); - assert(stdout.includes('[app_worker] exit with code:0')); + } yield coffee.fork(eggBin, [ 'stop', fixturePath ]) .debug() @@ -159,7 +179,7 @@ describe('test/stop.test.js', () => { yield utils.cleanup(fixturePath); yield coffee.fork(eggBin, [ 'stop', fixturePath ]) .debug() - .expect('stdout', new RegExp(`\\[egg-scripts] stopping egg application at ${fixturePath}`)) + .expect('stdout', new RegExp(`\\[egg-scripts] stopping egg application at ${fixturePathR}`)) .expect('stderr', /can't detect any running egg process/) .expect('code', 0) .end(); diff --git a/test/utils.js b/test/utils.js index 3e97e7a..ad0c6e5 100644 --- a/test/utils.js +++ b/test/utils.js @@ -3,8 +3,9 @@ const helper = require('../lib/helper'); const sleep = require('mz-modules/sleep'); -exports.cleanup = function* (baseDir) { - const processList = yield helper.findNodeProcess(x => x.cmd.includes(`"baseDir":"${baseDir}"`)); +exports.cleanup = function* (baseDir, port) { + port = port ? port : 7001; + const processList = yield helper.findNodeProcess(x => x.cmd.includes(`"baseDir":"${baseDir}"`), port); if (processList.length) { console.log(`cleanup: ${processList.length} to kill`); From eaf7ac4038d489aee44a99fcf1330551049c2474 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 18:21:23 +0800 Subject: [PATCH 02/11] feat: export helper.findNodeProcessWin() --- lib/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/helper.js b/lib/helper.js index 6f3c477..52214c2 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -68,6 +68,7 @@ function* findNodeProcessWin(port) { return processList; } +exports.findNodeProcessWin = findNodeProcessWin; exports.kill = function(pids, signal) { pids.forEach(pid => { From 6faa1e5ebdc443266a1b76d1215a0a0b2149b7c5 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 18:25:34 +0800 Subject: [PATCH 03/11] test: helper.findNodeProcessWin() --- test/stop.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/stop.test.js b/test/stop.test.js index af02c5d..c9c8400 100644 --- a/test/stop.test.js +++ b/test/stop.test.js @@ -10,6 +10,7 @@ const coffee = require('coffee'); const httpclient = require('urllib'); const mm = require('mm'); const utils = require('./utils'); +const helper = require('../lib/helper'); describe('test/stop.test.js', () => { const eggBin = require.resolve('../bin/egg-scripts.js'); @@ -172,6 +173,23 @@ describe('test/stop.test.js', () => { .expect('code', 0) .end(); }); + + if (process.platform === 'win32') { + it('should got pid', function* () { + const port = 7001; + const processList = yield helper.findNodeProcessWin(port); + + assert(Array.isArray(processList) && processList.length); + }); + + it('should got empty pid', function* () { + const port = 0; + const processList = yield helper.findNodeProcessWin(port); + + assert(Array.isArray(processList) && !processList.length); + }); + } + }); describe('stop with not exist', () => { From 28cf6f35e870118222ad6f198c1cd1b5c9a66438 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 19:02:49 +0800 Subject: [PATCH 04/11] feat: support win32 within checkStatus() --- lib/cmd/start.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/cmd/start.js b/lib/cmd/start.js index 5271f90..61a6a95 100644 --- a/lib/cmd/start.js +++ b/lib/cmd/start.js @@ -185,11 +185,21 @@ class StartCommand extends Command { try { const stat = yield fs.stat(stderr); if (stat && stat.size > 0) { - const [ stdout ] = yield exec('tail -n 100 ' + stderr); - this.logger.error(stdout); - this.logger.error('Start failed, see %s', stderr); - isSuccess = false; - break; + if (process.platform !== 'win23') { + const [ stdout ] = yield exec('tail -n 100 ' + stderr); + this.logger.error(stdout); + this.logger.error('Start failed, see %s', stderr); + isSuccess = false; + break; + } else { + let stdout = stderr.slice(0, 50000).replace(/\r/g, '\n'); + + stdout = stdout.split(/\n+/g).splice(0, 100); + this.logger.error(stdout); + this.logger.error('Start failed, see %s', stderr); + isSuccess = false; + break; + } } } catch (_) { // nothing From d4982e2a89352119493c10319586f88f53cc89fd Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 19:06:16 +0800 Subject: [PATCH 05/11] fix: win32 typo --- lib/cmd/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmd/start.js b/lib/cmd/start.js index 61a6a95..f0e2e0f 100644 --- a/lib/cmd/start.js +++ b/lib/cmd/start.js @@ -185,7 +185,7 @@ class StartCommand extends Command { try { const stat = yield fs.stat(stderr); if (stat && stat.size > 0) { - if (process.platform !== 'win23') { + if (process.platform !== 'win32') { const [ stdout ] = yield exec('tail -n 100 ' + stderr); this.logger.error(stdout); this.logger.error('Start failed, see %s', stderr); From 4fe668f44593599455f6358592ecf5bc8eee8981 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Tue, 7 Nov 2017 19:20:50 +0800 Subject: [PATCH 06/11] fix: convert stdout to string within checkStatus() --- lib/cmd/start.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cmd/start.js b/lib/cmd/start.js index f0e2e0f..550b514 100644 --- a/lib/cmd/start.js +++ b/lib/cmd/start.js @@ -192,9 +192,10 @@ class StartCommand extends Command { isSuccess = false; break; } else { - let stdout = stderr.slice(0, 50000).replace(/\r/g, '\n'); + const str = fs.readFileSync(stderr, 'utf-8'); + let stdout = str ? str.slice(0, 50000).replace(/\r/g, '\n') : ''; - stdout = stdout.split(/\n+/g).splice(0, 100); + stdout = stdout.split(/\n+/g).splice(0, 100).join('\n'); this.logger.error(stdout); this.logger.error('Start failed, see %s', stderr); isSuccess = false; From c3eda38da99cd57cbecf060084abba976d124f78 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 8 Nov 2017 10:06:54 +0800 Subject: [PATCH 07/11] dummy --- test/stop.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/stop.test.js b/test/stop.test.js index c9c8400..b975dfb 100644 --- a/test/stop.test.js +++ b/test/stop.test.js @@ -155,6 +155,7 @@ describe('test/stop.test.js', () => { assert(stdout.includes('[master] receive signal SIGTERM, closing')); assert(stdout.includes('[master] exit with code:0')); assert(stdout.includes('[app_worker] exit with code:0')); + } else { yield coffee.fork(eggBin, [ 'stop', fixturePath ]) .debug() From 7e63114948bacb73309e995d4a1d5af16e874b70 Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 8 Nov 2017 10:34:56 +0800 Subject: [PATCH 08/11] dummy --- test/start.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/start.test.js b/test/start.test.js index e940bf4..f4eb67f 100644 --- a/test/start.test.js +++ b/test/start.test.js @@ -437,3 +437,4 @@ describe('test/start.test.js', () => { }); }); + From 6b191d2496244187a507646b3b5df36a1d7c344d Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 8 Nov 2017 15:20:59 +0800 Subject: [PATCH 09/11] fix: drop duplicate pid value from ipv4/v6 within findNodeProcessWin() --- lib/helper.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/helper.js b/lib/helper.js index 52214c2..6e85056 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -41,32 +41,33 @@ function* findNodeProcessWin(port) { } catch (ex) { return []; } - const processList = stdio.stdout.toString().split('\n') - .reduce((arr, line) => { - if (line) { - // [ '', 'TCP', '0.0.0.0:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] - // [ '', 'TCP', '[::]:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] - const lineArr = line.split(/\s+/); + const map = new Map(); - if (!lineArr[0] && lineArr[1] === 'TCP' && lineArr[2] && lineArr[5]) { - const pid = lineArr[5]; - const ipArr = lineArr[2].split(':'); + stdio.stdout.toString().split('\n') + .forEach(line => { + if (line) { + // [ '', 'TCP', '0.0.0.0:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + // [ '', 'TCP', '[::]:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + const lineArr = line.split(/\s+/); - if (!Number.isSafeInteger(+pid)) { - return arr; - } + if (!lineArr[0] && lineArr[1] === 'TCP' && lineArr[2] && lineArr[5]) { + const pid = lineArr[5]; + const ipArr = lineArr[2].split(':'); - if (ipArr && ipArr.length >= 2) { - if (+ipArr[ipArr.length - 1] === port) { // ipv4/v6 - arr.push({ pid, cmd: '' }); + if (!Number.isSafeInteger(+pid) && map.has(pid)) { + return; + } + + if (ipArr && ipArr.length >= 2) { + if (+ipArr[ipArr.length - 1] === port) { // ipv4/v6 + map.set(pid, { pid, cmd: '' }); + } + } } - } } - } - return arr; - }, []); + }); - return processList; + return Array.from(map.values()); } exports.findNodeProcessWin = findNodeProcessWin; From 5fa56fb6a821c103169908248b84bf8c82e762ab Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Wed, 8 Nov 2017 16:35:11 +0800 Subject: [PATCH 10/11] Format style --- lib/helper.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/helper.js b/lib/helper.js index 6e85056..8d7c356 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -45,26 +45,26 @@ function* findNodeProcessWin(port) { stdio.stdout.toString().split('\n') .forEach(line => { - if (line) { - // [ '', 'TCP', '0.0.0.0:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] - // [ '', 'TCP', '[::]:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] - const lineArr = line.split(/\s+/); + if (line) { + // [ '', 'TCP', '0.0.0.0:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + // [ '', 'TCP', '[::]:7001', '0.0.0.0:0', 'LISTENING', '4580', '' ] + const lineArr = line.split(/\s+/); - if (!lineArr[0] && lineArr[1] === 'TCP' && lineArr[2] && lineArr[5]) { - const pid = lineArr[5]; - const ipArr = lineArr[2].split(':'); + if (!lineArr[0] && lineArr[1] === 'TCP' && lineArr[2] && lineArr[5]) { + const pid = lineArr[5]; + const ipArr = lineArr[2].split(':'); - if (!Number.isSafeInteger(+pid) && map.has(pid)) { - return; - } + if (!Number.isSafeInteger(+pid) && map.has(pid)) { + return; + } - if (ipArr && ipArr.length >= 2) { - if (+ipArr[ipArr.length - 1] === port) { // ipv4/v6 - map.set(pid, { pid, cmd: '' }); - } - } + if (ipArr && ipArr.length >= 2) { + if (+ipArr[ipArr.length - 1] === port) { // ipv4/v6 + map.set(pid, { pid, cmd: '' }); } + } } + } }); return Array.from(map.values()); From 03bd2f9ba3a9142483c5d5856e1f62ade157f28d Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Mon, 13 Nov 2017 21:18:48 +0800 Subject: [PATCH 11/11] Use yield instead of sync read --- lib/cmd/start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmd/start.js b/lib/cmd/start.js index 550b514..060a2c0 100644 --- a/lib/cmd/start.js +++ b/lib/cmd/start.js @@ -192,7 +192,7 @@ class StartCommand extends Command { isSuccess = false; break; } else { - const str = fs.readFileSync(stderr, 'utf-8'); + const str = yield fs.readFile(stderr, 'utf-8'); let stdout = str ? str.slice(0, 50000).replace(/\r/g, '\n') : ''; stdout = stdout.split(/\n+/g).splice(0, 100).join('\n');