lib: make sure clear the old timer in http server

PR-URL: https://github.com/nodejs/node/pull/52118
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
theanarkh authored and GitHub committed 2024-03-19 12:42:33 +00:00
1 parent 70a05103c8
commit 4e9ce7c035
2 files changed
+27

No files matched your search

+3
View File
@@ -515,6 +515,9 @@ function setupConnectionsTracking() {
this[kConnections] = new ConnectionsList();
}
if (this[kConnectionsCheckingInterval]) {
clearInterval(this[kConnectionsCheckingInterval]);
}
// This checker is started without checking whether any headersTimeout or requestTimeout is non zero
// otherwise it would not be started if such timeouts are modified after createServer.
this[kConnectionsCheckingInterval] =
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
const { kConnectionsCheckingInterval } = require('_http_server');
let i = 0;
let timer;
const server = http.createServer();
server.on('listening', common.mustCall(() => {
// If there was a timer, it must be destroyed
if (timer) {
assert.ok(timer._destroyed);
}
// Save the last timer
timer = server[kConnectionsCheckingInterval];
if (++i === 2) {
server.close(() => {
assert.ok(timer._destroyed);
});
}
}, 2));
server.emit('listening');
server.emit('listening');