Skip to content

Commit

Permalink
https: fix connection checking interval not clearing on
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/node#48373
PR-URL: nodejs/node#48383
Backport-PR-URL: nodejs/node#50194
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent 39ddf70 commit f12e1c1
Showing 6 changed files with 52 additions and 3 deletions.
9 changes: 8 additions & 1 deletion graal-nodejs/lib/_http_server.js
Original file line number Diff line number Diff line change
@@ -505,6 +505,11 @@ function setupConnectionsTracking() {
setInterval(checkConnections.bind(this), this.connectionsCheckingInterval).unref();
}

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

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

@@ -547,7 +552,7 @@ ObjectSetPrototypeOf(Server.prototype, net.Server.prototype);
ObjectSetPrototypeOf(Server, net.Server);

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

@@ -1190,4 +1195,6 @@ module.exports = {
storeHTTPOptions,
_connectionListener: connectionListener,
kServerResponse,
httpServerPreClose,
kConnectionsCheckingInterval,
};
7 changes: 7 additions & 0 deletions graal-nodejs/lib/https.js
Original file line number Diff line number Diff line change
@@ -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,
@@ -98,6 +100,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 {{
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { createServer } = require('http');
const { kConnectionsCheckingInterval } = require('_http_server');

const server = createServer(function(req, res) {});
server.listen(0, common.mustCall(function() {
assert.strictEqual(server[kConnectionsCheckingInterval]._destroyed, false);
server.close(common.mustCall(() => {
assert(server[kConnectionsCheckingInterval]._destroyed);
}));
}));
1 change: 0 additions & 1 deletion graal-nodejs/test/parallel/test-http-server-close-idle.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ server.listen(0, function() {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
assert.strictEqual(connections, 2);

server.closeIdleConnections();
server.close(common.mustCall());

// Check that only the idle connection got closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
const assert = require('assert');
if (!common.hasCrypto) {
common.skip('missing crypto');
}

const { createServer } = require('https');
const { kConnectionsCheckingInterval } = require('_http_server');

const fixtures = require('../common/fixtures');

const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
};

const server = createServer(options, function(req, res) {});
server.listen(0, common.mustCall(function() {
assert.strictEqual(server[kConnectionsCheckingInterval]._destroyed, false);
server.close(common.mustCall(() => {
assert(server[kConnectionsCheckingInterval]._destroyed);
}));
}));
1 change: 0 additions & 1 deletion graal-nodejs/test/parallel/test-https-server-close-idle.js
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ server.listen(0, function() {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
assert.strictEqual(connections, 2);

server.closeIdleConnections();
server.close(common.mustCall());

// Check that only the idle connection got closed

0 comments on commit f12e1c1

Please sign in to comment.