Skip to content

Commit d33fc36

Browse files
theanarkhmarco-ippolito
authored andcommitted
lib: make sure clear the old timer in http server
PR-URL: #52118 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent d6f9ca3 commit d33fc36

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/_http_server.js

+3
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ function setupConnectionsTracking() {
506506
this[kConnections] = new ConnectionsList();
507507
}
508508

509+
if (this[kConnectionsCheckingInterval]) {
510+
clearInterval(this[kConnectionsCheckingInterval]);
511+
}
509512
// This checker is started without checking whether any headersTimeout or requestTimeout is non zero
510513
// otherwise it would not be started if such timeouts are modified after createServer.
511514
this[kConnectionsCheckingInterval] =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const http = require('http');
4+
const assert = require('assert');
5+
const { kConnectionsCheckingInterval } = require('_http_server');
6+
7+
let i = 0;
8+
let timer;
9+
const server = http.createServer();
10+
server.on('listening', common.mustCall(() => {
11+
// If there was a timer, it must be destroyed
12+
if (timer) {
13+
assert.ok(timer._destroyed);
14+
}
15+
// Save the last timer
16+
timer = server[kConnectionsCheckingInterval];
17+
if (++i === 2) {
18+
server.close(() => {
19+
assert.ok(timer._destroyed);
20+
});
21+
}
22+
}, 2));
23+
server.emit('listening');
24+
server.emit('listening');

0 commit comments

Comments
 (0)