Skip to content

Commit

Permalink
https: fix connection checking interval not clearing on server close
Browse files Browse the repository at this point in the history
The connection interval should close when httpsServer.close is called
similarly to how it gets cleared when httpServer.close is called.

fixes: nodejs#48373
  • Loading branch information
Linkgoron committed Jun 7, 2023
1 parent 1d1685e commit af60e03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ function setupConnectionsTracking(server) {
setInterval(checkConnections.bind(server), server.connectionsCheckingInterval).unref();
}

function httpServerPreClose(server) {
server.closeIdleConnections();
clearInterval(server[kConnectionsCheckingInterval]);
}

function Server(options, requestListener) {
if (!(this instanceof Server)) return new Server(options, requestListener);

Expand Down Expand Up @@ -548,8 +553,7 @@ ObjectSetPrototypeOf(Server.prototype, net.Server.prototype);
ObjectSetPrototypeOf(Server, net.Server);

Server.prototype.close = function() {
this.closeIdleConnections();
clearInterval(this[kConnectionsCheckingInterval]);
httpServerPreClose(this);
ReflectApply(net.Server.prototype.close, this, arguments);
};

Expand Down Expand Up @@ -1193,4 +1197,5 @@ module.exports = {
storeHTTPOptions,
_connectionListener: connectionListener,
kServerResponse,
httpServerPreClose,
};
7 changes: 7 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const {
JSONStringify,
ObjectAssign,
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
} = primordials;

Expand All @@ -43,6 +44,7 @@ assertCrypto();
const tls = require('tls');
const { Agent: HttpAgent } = require('_http_agent');
const {
httpServerPreClose,
Server: HttpServer,
setupConnectionsTracking,
storeHTTPOptions,
Expand Down Expand Up @@ -103,6 +105,11 @@ Server.prototype.closeIdleConnections = HttpServer.prototype.closeIdleConnection

Server.prototype.setTimeout = HttpServer.prototype.setTimeout;

Server.prototype.close = function() {
httpServerPreClose(this);
ReflectApply(tls.Server.prototype.close, this, arguments);
};

/**
* Creates a new `https.Server` instance.
* @param {{
Expand Down

0 comments on commit af60e03

Please sign in to comment.