Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 40ae6eb

Browse filesBrowse files
LinkgoronRafaelGSS
authored andcommitted
https: fix connection checking interval not clearing on server close
The connection interval should close when httpsServer.close is called similarly to how it gets cleared when httpServer.close is called. fixes: #48373 PR-URL: #48383 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>
1 parent e9c9d18 commit 40ae6eb
Copy full SHA for 40ae6eb

File tree

Expand file treeCollapse file tree

6 files changed

+52
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+52
-4
lines changed
Open diff view settings
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ function setupConnectionsTracking(server) {
507507
setInterval(checkConnections.bind(server), server.connectionsCheckingInterval).unref();
508508
}
509509

510+
function httpServerPreClose(server) {
511+
server.closeIdleConnections();
512+
clearInterval(server[kConnectionsCheckingInterval]);
513+
}
514+
510515
function Server(options, requestListener) {
511516
if (!(this instanceof Server)) return new Server(options, requestListener);
512517

@@ -548,8 +553,7 @@ ObjectSetPrototypeOf(Server.prototype, net.Server.prototype);
548553
ObjectSetPrototypeOf(Server, net.Server);
549554

550555
Server.prototype.close = function() {
551-
this.closeIdleConnections();
552-
clearInterval(this[kConnectionsCheckingInterval]);
556+
httpServerPreClose(this);
553557
ReflectApply(net.Server.prototype.close, this, arguments);
554558
};
555559

@@ -1193,4 +1197,6 @@ module.exports = {
11931197
storeHTTPOptions,
11941198
_connectionListener: connectionListener,
11951199
kServerResponse,
1200+
httpServerPreClose,
1201+
kConnectionsCheckingInterval,
11961202
};
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const {
3131
JSONStringify,
3232
ObjectAssign,
3333
ObjectSetPrototypeOf,
34+
ReflectApply,
3435
ReflectConstruct,
3536
} = primordials;
3637

@@ -43,6 +44,7 @@ assertCrypto();
4344
const tls = require('tls');
4445
const { Agent: HttpAgent } = require('_http_agent');
4546
const {
47+
httpServerPreClose,
4648
Server: HttpServer,
4749
setupConnectionsTracking,
4850
storeHTTPOptions,
@@ -103,6 +105,11 @@ Server.prototype.closeIdleConnections = HttpServer.prototype.closeIdleConnection
103105

104106
Server.prototype.setTimeout = HttpServer.prototype.setTimeout;
105107

108+
Server.prototype.close = function() {
109+
httpServerPreClose(this);
110+
ReflectApply(tls.Server.prototype.close, this, arguments);
111+
};
112+
106113
/**
107114
* Creates a new `https.Server` instance.
108115
* @param {{
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { createServer } = require('http');
5+
const { kConnectionsCheckingInterval } = require('_http_server');
6+
7+
const server = createServer(function(req, res) {});
8+
server.listen(0, common.mustCall(function() {
9+
assert.strictEqual(server[kConnectionsCheckingInterval]._destroyed, false);
10+
server.close(common.mustCall(() => {
11+
assert(server[kConnectionsCheckingInterval]._destroyed);
12+
}));
13+
}));
Collapse file

‎test/parallel/test-http-server-close-idle.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-server-close-idle.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ server.listen(0, function() {
4242
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
4343
assert.strictEqual(connections, 2);
4444

45-
server.closeIdleConnections();
4645
server.close(common.mustCall());
4746

4847
// Check that only the idle connection got closed
Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
if (!common.hasCrypto) {
5+
common.skip('missing crypto');
6+
}
7+
8+
const { createServer } = require('https');
9+
const { kConnectionsCheckingInterval } = require('_http_server');
10+
11+
const fixtures = require('../common/fixtures');
12+
13+
const options = {
14+
key: fixtures.readKey('agent1-key.pem'),
15+
cert: fixtures.readKey('agent1-cert.pem')
16+
};
17+
18+
const server = createServer(options, function(req, res) {});
19+
server.listen(0, common.mustCall(function() {
20+
assert.strictEqual(server[kConnectionsCheckingInterval]._destroyed, false);
21+
server.close(common.mustCall(() => {
22+
assert(server[kConnectionsCheckingInterval]._destroyed);
23+
}));
24+
}));
Collapse file

‎test/parallel/test-https-server-close-idle.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-https-server-close-idle.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ server.listen(0, function() {
5252
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
5353
assert.strictEqual(connections, 2);
5454

55-
server.closeIdleConnections();
5655
server.close(common.mustCall());
5756

5857
// Check that only the idle connection got closed

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.