Skip to content
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: skip specified Node.js version to set keep-alive #4527

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/middleware/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
const semver = require('semver');

module.exports = options => {
// 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');
// Node.js >= 14.8.0 && < 14.12.0 and = 12.19.0 will set Keep-Alive Header
// Refs: https://github.com/nodejs/node/pull/34561 https://github.com/nodejs/node/pull/35138

const shouldPatchKeepAliveHeader = !semver.satisfies(process.version, '>=14.8.0 <14.12.0 || =12.19.0');
atian25 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这逻辑有问题吧,在 14.12.0 之上的版本,都不应该 patch 了,交给 Node 本身来 patch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看错了,close


return async function meta(ctx, next) {
if (options.logging) {
Expand All @@ -18,7 +20,6 @@ module.exports = options => {
// total response time header
ctx.set('x-readtime', Date.now() - ctx.starttime);

// try to support Keep-Alive Header when < 14.8.0
const server = ctx.app.server;
if (shouldPatchKeepAliveHeader && server && server.keepAliveTimeout && server.keepAliveTimeout >= 1000 && ctx.header.connection !== 'close') {
/**
Expand Down