Skip to content

Commit

Permalink
lib: make sure clear the old timer in http server
Browse files Browse the repository at this point in the history
PR-URL: #52118
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
theanarkh authored and marco-ippolito committed May 3, 2024
1 parent d6f9ca3 commit d33fc36
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,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] =
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-http-server-clear-timer.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit d33fc36

Please sign in to comment.