Skip to content

Commit

Permalink
http2: close idle connections when allowHTTP1 is true
Browse files Browse the repository at this point in the history
  • Loading branch information
xsbchen committed Jan 26, 2024
1 parent 09da597 commit 5c54736
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const {
kIncomingMessage,
_checkIsHttpToken: checkIsHttpToken,
} = require('_http_common');
const { kServerResponse } = require('_http_server');
const { kServerResponse, Server: HttpServer, setupConnectionsTracking } = require('_http_server');
const JSStreamSocket = require('internal/js_stream_socket');

const {
Expand Down Expand Up @@ -3180,13 +3180,22 @@ class Http2SecureServer extends TLSServer {
this[kOptions] = options;
this.timeout = 0;
this.on('newListener', setupCompat);
if (options.allowHTTP1 === true) {
this.headersTimeout = 0;
this.requestTimeout = 0;
this.on('listening', setupConnectionsTracking);
}
if (typeof requestListener === 'function')
this.on('request', requestListener);
this.on('tlsClientError', onErrorSecureServerSession);
}

setTimeout(msecs, callback) {
this.timeout = msecs;
if (this[kOptions].allowHTTP1 === true) {
this.headersTimeout = msecs;
this.requestTimeout = msecs;
}
if (callback !== undefined) {
validateFunction(callback, 'callback');
this.on('timeout', callback);
Expand All @@ -3199,6 +3208,13 @@ class Http2SecureServer extends TLSServer {
validateSettings(settings);
this[kOptions].settings = { ...this[kOptions].settings, ...settings };
}

close() {
if (this[kOptions].allowHTTP1 === true) {
FunctionPrototypeCall(HttpServer.prototype.closeIdleConnections, this);
}
ReflectApply(TLSServer.prototype.close, this, arguments);
}
}

class Http2Server extends NETServer {
Expand Down

0 comments on commit 5c54736

Please sign in to comment.