@@ -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++) { |
|