| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 045e3c5 commit 742597b
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -500,14 +500,16 @@ function storeHTTPOptions(options) { | |||
| 500 | 500 | } | |
| 501 | 501 | } | |
| 502 | 502 | ||
| 503 | - function setupConnectionsTracking(server) { | ||
| 503 | + function setupConnectionsTracking() { | ||
| 504 | 504 | // Start connection handling | |
| 505 | - server[kConnections] = new ConnectionsList(); | ||
| 505 | + if (!this[kConnections]) { | ||
| 506 | + this[kConnections] = new ConnectionsList(); | ||
| 507 | + } | ||
| 506 | 508 | ||
| 507 | 509 | // This checker is started without checking whether any headersTimeout or requestTimeout is non zero | |
| 508 | 510 | // otherwise it would not be started if such timeouts are modified after createServer. | |
| 509 | - server[kConnectionsCheckingInterval] = | ||
| 510 | - setInterval(checkConnections.bind(server), server.connectionsCheckingInterval).unref(); | ||
| 511 | + this[kConnectionsCheckingInterval] = | ||
| 512 | + setInterval(checkConnections.bind(this), this.connectionsCheckingInterval).unref(); | ||
| 511 | 513 | } | |
| 512 | 514 | ||
| 513 | 515 | function httpServerPreClose(server) { | |
@@ -545,11 +547,12 @@ function Server(options, requestListener) { | |||
| 545 | 547 | this.httpAllowHalfOpen = false; | |
| 546 | 548 | ||
| 547 | 549 | this.on('connection', connectionListener); | |
| 550 | + this.on('listening', setupConnectionsTracking); | ||
| 548 | 551 | ||
| 549 | 552 | this.timeout = 0; | |
| 550 | 553 | this.maxHeadersCount = null; | |
| 551 | 554 | this.maxRequestsPerSocket = 0; | |
| 552 | - setupConnectionsTracking(this); | ||
| 555 | + | ||
| 553 | 556 | this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders); | |
| 554 | 557 | } | |
| 555 | 558 | ObjectSetPrototypeOf(Server.prototype, net.Server.prototype); | |
@@ -565,6 +568,10 @@ Server.prototype[SymbolAsyncDispose] = async function() { | |||
| 565 | 568 | }; | |
| 566 | 569 | ||
| 567 | 570 | Server.prototype.closeAllConnections = function() { | |
| 571 | + if (!this[kConnections]) { | ||
| 572 | + return; | ||
| 573 | + } | ||
| 574 | + | ||
| 568 | 575 | const connections = this[kConnections].all(); | |
| 569 | 576 | ||
| 570 | 577 | for (let i = 0, l = connections.length; i < l; i++) { | |
@@ -573,6 +580,10 @@ Server.prototype.closeAllConnections = function() { | |||
| 573 | 580 | }; | |
| 574 | 581 | ||
| 575 | 582 | Server.prototype.closeIdleConnections = function() { | |
| 583 | + if (!this[kConnections]) { | ||
| 584 | + return; | ||
| 585 | + } | ||
| 586 | + | ||
| 576 | 587 | const connections = this[kConnections].idle(); | |
| 577 | 588 | ||
| 578 | 589 | for (let i = 0, l = connections.length; i < l; i++) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,8 +96,9 @@ function Server(opts, requestListener) { | |||
| 96 | 96 | ||
| 97 | 97 | this.timeout = 0; | |
| 98 | 98 | this.maxHeadersCount = null; | |
| 99 | - setupConnectionsTracking(this); | ||
| 99 | + this.on('listening', setupConnectionsTracking); | ||
| 100 | 100 | } | |
| 101 | + | ||
| 101 | 102 | ObjectSetPrototypeOf(Server.prototype, tls.Server.prototype); | |
| 102 | 103 | ObjectSetPrototypeOf(Server, tls.Server); | |
| 103 | 104 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --expose-gc | ||
| 4 | + | ||
| 5 | + // Check that creating a server without listening does not leak resources. | ||
| 6 | + | ||
| 7 | + require('../common'); | ||
| 8 | + const onGC = require('../common/ongc'); | ||
| 9 | + const Countdown = require('../common/countdown'); | ||
| 10 | + | ||
| 11 | + const http = require('http'); | ||
| 12 | + const max = 100; | ||
| 13 | + | ||
| 14 | + // Note that Countdown internally calls common.mustCall, that's why it's not done here. | ||
| 15 | + const countdown = new Countdown(max, () => {}); | ||
| 16 | + | ||
| 17 | + for (let i = 0; i < max; i++) { | ||
| 18 | + const server = http.createServer((req, res) => {}); | ||
| 19 | + onGC(server, { ongc: countdown.dec.bind(countdown) }); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + setImmediate(() => { | ||
| 23 | + global.gc(); | ||
| 24 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --expose-gc | ||
| 4 | + | ||
| 5 | + // Check that creating a server without listening does not leak resources. | ||
| 6 | + | ||
| 7 | + const common = require('../common'); | ||
| 8 | + | ||
| 9 | + if (!common.hasCrypto) { | ||
| 10 | + common.skip('missing crypto'); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + const onGC = require('../common/ongc'); | ||
| 14 | + const Countdown = require('../common/countdown'); | ||
| 15 | + | ||
| 16 | + const https = require('https'); | ||
| 17 | + const max = 100; | ||
| 18 | + | ||
| 19 | + // Note that Countdown internally calls common.mustCall, that's why it's not done here. | ||
| 20 | + const countdown = new Countdown(max, () => {}); | ||
| 21 | + | ||
| 22 | + for (let i = 0; i < max; i++) { | ||
| 23 | + const server = https.createServer((req, res) => {}); | ||
| 24 | + onGC(server, { ongc: countdown.dec.bind(countdown) }); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + setImmediate(() => { | ||
| 28 | + global.gc(); | ||
| 29 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments