diff --git a/lib/_http_server.js b/lib/_http_server.js index c6a070115569ad..f28ca3a53804ab 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -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); @@ -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); }; @@ -1193,4 +1197,5 @@ module.exports = { storeHTTPOptions, _connectionListener: connectionListener, kServerResponse, + httpServerPreClose, }; diff --git a/lib/https.js b/lib/https.js index ad67a2f7244bd6..ca695555640a32 100644 --- a/lib/https.js +++ b/lib/https.js @@ -31,6 +31,7 @@ const { JSONStringify, ObjectAssign, ObjectSetPrototypeOf, + ReflectApply, ReflectConstruct, } = primordials; @@ -43,6 +44,7 @@ assertCrypto(); const tls = require('tls'); const { Agent: HttpAgent } = require('_http_agent'); const { + httpServerPreClose, Server: HttpServer, setupConnectionsTracking, storeHTTPOptions, @@ -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 {{