From 9f653afe790e0ead44109c68dfffb8353fdca56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TZ=20=7C=20=E5=A4=A9=E7=8C=AA?= Date: Mon, 19 Oct 2020 17:20:36 +0800 Subject: [PATCH] fix: remove clear timing && skip keep-alive after 12.19.0 (#4497) --- app/middleware/meta.js | 4 ++-- lib/egg.js | 2 +- test/lib/egg.test.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/middleware/meta.js b/app/middleware/meta.js index 519bcebe2e..680d115ffc 100644 --- a/app/middleware/meta.js +++ b/app/middleware/meta.js @@ -7,8 +7,8 @@ const semver = require('semver'); module.exports = options => { - // Node.js >=14.8.0 will set Keep-Alive Header, see https://github.com/nodejs/node/pull/34561 - const shouldPatchKeepAliveHeader = semver.lt(process.version, '14.8.0'); + // Node.js >=14.8.0 and >= 12.19.0 will set Keep-Alive Header, see https://github.com/nodejs/node/pull/34561 + const shouldPatchKeepAliveHeader = !semver.satisfies(process.version, '>=14.8.0 || ^12.19.0'); return async function meta(ctx, next) { if (options.logging) { diff --git a/lib/egg.js b/lib/egg.js index 3fb2078f76..b2410e0d51 100644 --- a/lib/egg.js +++ b/lib/egg.js @@ -411,7 +411,7 @@ class EggApplication extends EggCore { const rundir = this.config.rundir; const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`); fs.writeFileSync(dumpFile, CircularJSON.stringify(json, null, 2)); - this.timing.clear(); + // only disable, not clear bootstrap timing data. this.timing.disable(); } catch (err) { this.coreLogger.warn(`dumpTiming error: ${err.message}`); diff --git a/test/lib/egg.test.js b/test/lib/egg.test.js index a4e582c85f..433e47c337 100644 --- a/test/lib/egg.test.js +++ b/test/lib/egg.test.js @@ -146,13 +146,13 @@ describe('test/lib/egg.test.js', () => { assert(json[0].pid === process.pid); }); - it('should disable & clear timing after ready', function* () { + it('should disable timing after ready', function* () { const json = app.timing.toJSON(); - assert(json.length === 0); + const last = json[json.length - 1]; app.timing.start('a'); app.timing.end('a'); const json2 = app.timing.toJSON(); - assert(json2.length === 0); + assert(json2[json.length - 1].name === last.name); }); it('should ignore error when dumpTiming', done => {