From 3bcd68337eab2bd9d729672999f9849a022472b8 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 28 Apr 2024 13:18:07 -0600 Subject: [PATCH] http2: fix excessive CPU usage when using `allowHTTP1=true` When Http2SecureServer is configured with `allowHTTP1=true`, it calls `setupConnectionsTracking` to start monitoring for idle HTTP1 connections. `setupConnectionsTracking` expects to have `this.connectionsCheckingInterval` property defined, but it does not exist on `Http2SecureServer`. This `undefined` value is passed to `setInterval`, which results in `checkConnections` being called on every tick, creating significant additional load on the server CPU. The fix is to define `this.connectionsCheckingInterval` on the Http2SecureServer instance. Refs: https://github.com/nodejs/node/pull/51569 PR-URL: https://github.com/nodejs/node/pull/52713 Reviewed-By: Yagiz Nizipli Reviewed-By: Paolo Insogna Reviewed-By: Matteo Collina Reviewed-By: Marco Ippolito Reviewed-By: Luigi Pinca Reviewed-By: Rafael Gonzaga Reviewed-By: Moshe Atlow --- lib/internal/http2/core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 97d59ae5520ca8..761e871378848f 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -3185,6 +3185,7 @@ class Http2SecureServer extends TLSServer { if (options.allowHTTP1 === true) { this.headersTimeout = 60_000; // Minimum between 60 seconds or requestTimeout this.requestTimeout = 300_000; // 5 minutes + this.connectionsCheckingInterval = 30_000; // 30 seconds this.on('listening', setupConnectionsTracking); } if (typeof requestListener === 'function')