@@ -497,14 +497,14 @@ function storeHTTPOptions(options) {
497497 }
498498}
499499
500- function setupConnectionsTracking ( server ) {
500+ function setupConnectionsTracking ( ) {
501501 // Start connection handling
502- server [ kConnections ] = new ConnectionsList ( ) ;
502+ this [ kConnections ] = new ConnectionsList ( ) ;
503503
504504 // This checker is started without checking whether any headersTimeout or requestTimeout is non zero
505505 // otherwise it would not be started if such timeouts are modified after createServer.
506- server [ kConnectionsCheckingInterval ] =
507- setInterval ( checkConnections . bind ( server ) , server . connectionsCheckingInterval ) . unref ( ) ;
506+ this [ kConnectionsCheckingInterval ] =
507+ setInterval ( checkConnections . bind ( this ) , this . connectionsCheckingInterval ) . unref ( ) ;
508508}
509509
510510function httpServerPreClose ( server ) {
@@ -542,11 +542,12 @@ function Server(options, requestListener) {
542542 this . httpAllowHalfOpen = false ;
543543
544544 this . on ( 'connection' , connectionListener ) ;
545+ this . on ( 'listening' , setupConnectionsTracking ) ;
545546
546547 this . timeout = 0 ;
547548 this . maxHeadersCount = null ;
548549 this . maxRequestsPerSocket = 0 ;
549- setupConnectionsTracking ( this ) ;
550+
550551 this [ kUniqueHeaders ] = parseUniqueHeadersOption ( options . uniqueHeaders ) ;
551552}
552553ObjectSetPrototypeOf ( Server . prototype , net . Server . prototype ) ;
@@ -558,6 +559,10 @@ Server.prototype.close = function() {
558559} ;
559560
560561Server . prototype . closeAllConnections = function ( ) {
562+ if ( ! this [ kConnections ] ) {
563+ return ;
564+ }
565+
561566 const connections = this [ kConnections ] . all ( ) ;
562567
563568 for ( let i = 0 , l = connections . length ; i < l ; i ++ ) {
@@ -566,6 +571,10 @@ Server.prototype.closeAllConnections = function() {
566571} ;
567572
568573Server . prototype . closeIdleConnections = function ( ) {
574+ if ( ! this [ kConnections ] ) {
575+ return ;
576+ }
577+
569578 const connections = this [ kConnections ] . idle ( ) ;
570579
571580 for ( let i = 0 , l = connections . length ; i < l ; i ++ ) {
0 commit comments