| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cb43717 commit 8874b2e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -493,14 +493,16 @@ function storeHTTPOptions(options) { | |||
| 493 | 493 | } | |
| 494 | 494 | } | |
| 495 | 495 | ||
| 496 | - function setupConnectionsTracking(server) { | ||
| 496 | + function setupConnectionsTracking() { | ||
| 497 | 497 | // Start connection handling | |
| 498 | - server[kConnections] = new ConnectionsList(); | ||
| 498 | + if (!this[kConnections]) { | ||
| 499 | + this[kConnections] = new ConnectionsList(); | ||
| 500 | + } | ||
| 499 | 501 | ||
| 500 | 502 | // This checker is started without checking whether any headersTimeout or requestTimeout is non zero | |
| 501 | 503 | // otherwise it would not be started if such timeouts are modified after createServer. | |
| 502 | - server[kConnectionsCheckingInterval] = | ||
| 503 | - setInterval(checkConnections.bind(server), server.connectionsCheckingInterval).unref(); | ||
| 504 | + this[kConnectionsCheckingInterval] = | ||
| 505 | + setInterval(checkConnections.bind(this), this.connectionsCheckingInterval).unref(); | ||
| 504 | 506 | } | |
| 505 | 507 | ||
| 506 | 508 | function Server(options, requestListener) { | |
@@ -533,11 +535,12 @@ function Server(options, requestListener) { | |||
| 533 | 535 | this.httpAllowHalfOpen = false; | |
| 534 | 536 | ||
| 535 | 537 | this.on('connection', connectionListener); | |
| 538 | + this.on('listening', setupConnectionsTracking); | ||
| 536 | 539 | ||
| 537 | 540 | this.timeout = 0; | |
| 538 | 541 | this.maxHeadersCount = null; | |
| 539 | 542 | this.maxRequestsPerSocket = 0; | |
| 540 | - setupConnectionsTracking(this); | ||
| 543 | + | ||
| 541 | 544 | this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders); | |
| 542 | 545 | } | |
| 543 | 546 | ObjectSetPrototypeOf(Server.prototype, net.Server.prototype); | |
@@ -549,6 +552,10 @@ Server.prototype.close = function() { | |||
| 549 | 552 | }; | |
| 550 | 553 | ||
| 551 | 554 | Server.prototype.closeAllConnections = function() { | |
| 555 | + if (!this[kConnections]) { | ||
| 556 | + return; | ||
| 557 | + } | ||
| 558 | + | ||
| 552 | 559 | const connections = this[kConnections].all(); | |
| 553 | 560 | ||
| 554 | 561 | for (let i = 0, l = connections.length; i < l; i++) { | |
@@ -557,6 +564,10 @@ Server.prototype.closeAllConnections = function() { | |||
| 557 | 564 | }; | |
| 558 | 565 | ||
| 559 | 566 | Server.prototype.closeIdleConnections = function() { | |
| 567 | + if (!this[kConnections]) { | ||
| 568 | + return; | ||
| 569 | + } | ||
| 570 | + | ||
| 560 | 571 | const connections = this[kConnections].idle(); | |
| 561 | 572 | ||
| 562 | 573 | for (let i = 0, l = connections.length; i < l; i++) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,8 +86,9 @@ function Server(opts, requestListener) { | |||
| 86 | 86 | ||
| 87 | 87 | this.timeout = 0; | |
| 88 | 88 | this.maxHeadersCount = null; | |
| 89 | - setupConnectionsTracking(this); | ||
| 89 | + this.on('listening', setupConnectionsTracking); | ||
| 90 | 90 | } | |
| 91 | + | ||
| 91 | 92 | ObjectSetPrototypeOf(Server.prototype, tls.Server.prototype); | |
| 92 | 93 | ObjectSetPrototypeOf(Server, tls.Server); | |
| 93 | 94 | ||
| 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