@@ -430,27 +430,36 @@ export class Server {
430
430
port : boundAddress . port
431
431
}
432
432
}
433
- const channelzRef = registerChannelzSocket ( subchannelAddressToString ( boundSubchannelAddress ) , ( ) => {
434
- return {
435
- localAddress : boundSubchannelAddress ,
436
- remoteAddress : null ,
437
- security : null ,
438
- remoteName : null ,
439
- streamsStarted : 0 ,
440
- streamsSucceeded : 0 ,
441
- streamsFailed : 0 ,
442
- messagesSent : 0 ,
443
- messagesReceived : 0 ,
444
- keepAlivesSent : 0 ,
445
- lastLocalStreamCreatedTimestamp : null ,
446
- lastRemoteStreamCreatedTimestamp : null ,
447
- lastMessageSentTimestamp : null ,
448
- lastMessageReceivedTimestamp : null ,
449
- localFlowControlWindow : null ,
450
- remoteFlowControlWindow : null
433
+ let channelzRef : SocketRef ;
434
+ if ( this . channelzEnabled ) {
435
+ channelzRef = registerChannelzSocket ( subchannelAddressToString ( boundSubchannelAddress ) , ( ) => {
436
+ return {
437
+ localAddress : boundSubchannelAddress ,
438
+ remoteAddress : null ,
439
+ security : null ,
440
+ remoteName : null ,
441
+ streamsStarted : 0 ,
442
+ streamsSucceeded : 0 ,
443
+ streamsFailed : 0 ,
444
+ messagesSent : 0 ,
445
+ messagesReceived : 0 ,
446
+ keepAlivesSent : 0 ,
447
+ lastLocalStreamCreatedTimestamp : null ,
448
+ lastRemoteStreamCreatedTimestamp : null ,
449
+ lastMessageSentTimestamp : null ,
450
+ lastMessageReceivedTimestamp : null ,
451
+ localFlowControlWindow : null ,
452
+ remoteFlowControlWindow : null
453
+ } ;
454
+ } ) ;
455
+ this . listenerChildrenTracker . refChild ( channelzRef ) ;
456
+ } else {
457
+ channelzRef = {
458
+ kind : 'socket' ,
459
+ id : - 1 ,
460
+ name : ''
451
461
} ;
452
- } ) ;
453
- this . listenerChildrenTracker . refChild ( channelzRef ) ;
462
+ }
454
463
this . http2ServerList . push ( { server : http2Server , channelzRef : channelzRef } ) ;
455
464
this . trace ( 'Successfully bound ' + subchannelAddressToString ( boundSubchannelAddress ) ) ;
456
465
resolve ( 'port' in boundSubchannelAddress ? boundSubchannelAddress . port : portNum ) ;
@@ -499,27 +508,36 @@ export class Server {
499
508
host : boundAddress . address ,
500
509
port : boundAddress . port
501
510
} ;
502
- const channelzRef = registerChannelzSocket ( subchannelAddressToString ( boundSubchannelAddress ) , ( ) => {
503
- return {
504
- localAddress : boundSubchannelAddress ,
505
- remoteAddress : null ,
506
- security : null ,
507
- remoteName : null ,
508
- streamsStarted : 0 ,
509
- streamsSucceeded : 0 ,
510
- streamsFailed : 0 ,
511
- messagesSent : 0 ,
512
- messagesReceived : 0 ,
513
- keepAlivesSent : 0 ,
514
- lastLocalStreamCreatedTimestamp : null ,
515
- lastRemoteStreamCreatedTimestamp : null ,
516
- lastMessageSentTimestamp : null ,
517
- lastMessageReceivedTimestamp : null ,
518
- localFlowControlWindow : null ,
519
- remoteFlowControlWindow : null
511
+ let channelzRef : SocketRef ;
512
+ if ( this . channelzEnabled ) {
513
+ channelzRef = registerChannelzSocket ( subchannelAddressToString ( boundSubchannelAddress ) , ( ) => {
514
+ return {
515
+ localAddress : boundSubchannelAddress ,
516
+ remoteAddress : null ,
517
+ security : null ,
518
+ remoteName : null ,
519
+ streamsStarted : 0 ,
520
+ streamsSucceeded : 0 ,
521
+ streamsFailed : 0 ,
522
+ messagesSent : 0 ,
523
+ messagesReceived : 0 ,
524
+ keepAlivesSent : 0 ,
525
+ lastLocalStreamCreatedTimestamp : null ,
526
+ lastRemoteStreamCreatedTimestamp : null ,
527
+ lastMessageSentTimestamp : null ,
528
+ lastMessageReceivedTimestamp : null ,
529
+ localFlowControlWindow : null ,
530
+ remoteFlowControlWindow : null
531
+ } ;
532
+ } ) ;
533
+ this . listenerChildrenTracker . refChild ( channelzRef ) ;
534
+ } else {
535
+ channelzRef = {
536
+ kind : 'socket' ,
537
+ id : - 1 ,
538
+ name : ''
520
539
} ;
521
- } ) ;
522
- this . listenerChildrenTracker . refChild ( channelzRef ) ;
540
+ }
523
541
this . http2ServerList . push ( { server : http2Server , channelzRef : channelzRef } ) ;
524
542
this . trace ( 'Successfully bound ' + subchannelAddressToString ( boundSubchannelAddress ) ) ;
525
543
resolve (
@@ -599,8 +617,10 @@ export class Server {
599
617
for ( const { server : http2Server , channelzRef : ref } of this . http2ServerList ) {
600
618
if ( http2Server . listening ) {
601
619
http2Server . close ( ( ) => {
602
- this . listenerChildrenTracker . unrefChild ( ref ) ;
603
- unregisterChannelzRef ( ref ) ;
620
+ if ( this . channelzEnabled ) {
621
+ this . listenerChildrenTracker . unrefChild ( ref ) ;
622
+ unregisterChannelzRef ( ref ) ;
623
+ }
604
624
} ) ;
605
625
}
606
626
}
@@ -616,7 +636,9 @@ export class Server {
616
636
session . destroy ( http2 . constants . NGHTTP2_CANCEL as any ) ;
617
637
} ) ;
618
638
this . sessions . clear ( ) ;
619
- unregisterChannelzRef ( this . channelzRef ) ;
639
+ if ( this . channelzEnabled ) {
640
+ unregisterChannelzRef ( this . channelzRef ) ;
641
+ }
620
642
}
621
643
622
644
register < RequestType , ResponseType > (
@@ -665,7 +687,9 @@ export class Server {
665
687
666
688
tryShutdown ( callback : ( error ?: Error ) => void ) : void {
667
689
const wrappedCallback = ( error ?: Error ) => {
668
- unregisterChannelzRef ( this . channelzRef ) ;
690
+ if ( this . channelzEnabled ) {
691
+ unregisterChannelzRef ( this . channelzRef ) ;
692
+ }
669
693
callback ( error ) ;
670
694
} ;
671
695
let pendingChecks = 0 ;
@@ -685,8 +709,10 @@ export class Server {
685
709
if ( http2Server . listening ) {
686
710
pendingChecks ++ ;
687
711
http2Server . close ( ( ) => {
688
- this . listenerChildrenTracker . unrefChild ( ref ) ;
689
- unregisterChannelzRef ( ref ) ;
712
+ if ( this . channelzEnabled ) {
713
+ this . listenerChildrenTracker . unrefChild ( ref ) ;
714
+ unregisterChannelzRef ( ref ) ;
715
+ }
690
716
maybeCallback ( ) ;
691
717
} ) ;
692
718
}
@@ -727,8 +753,10 @@ export class Server {
727
753
'stream' ,
728
754
( stream : http2 . ServerHttp2Stream , headers : http2 . IncomingHttpHeaders ) => {
729
755
const channelzSessionInfo = this . sessions . get ( stream . session as http2 . ServerHttp2Session ) ;
730
- this . callTracker . addCallStarted ( ) ;
731
- channelzSessionInfo ?. streamTracker . addCallStarted ( ) ;
756
+ if ( this . channelzEnabled ) {
757
+ this . callTracker . addCallStarted ( ) ;
758
+ channelzSessionInfo ?. streamTracker . addCallStarted ( ) ;
759
+ }
732
760
const contentType = headers [ http2 . constants . HTTP2_HEADER_CONTENT_TYPE ] ;
733
761
734
762
if (
@@ -743,7 +771,9 @@ export class Server {
743
771
{ endStream : true }
744
772
) ;
745
773
this . callTracker . addCallFailed ( ) ;
746
- channelzSessionInfo ?. streamTracker . addCallFailed ( ) ;
774
+ if ( this . channelzEnabled ) {
775
+ channelzSessionInfo ?. streamTracker . addCallFailed ( ) ;
776
+ }
747
777
return ;
748
778
}
749
779
@@ -786,7 +816,7 @@ export class Server {
786
816
this . callTracker . addCallFailed ( ) ;
787
817
}
788
818
} ) ;
789
- if ( channelzSessionInfo ) {
819
+ if ( this . channelzEnabled && channelzSessionInfo ) {
790
820
call . once ( 'streamEnd' , ( success : boolean ) => {
791
821
if ( success ) {
792
822
channelzSessionInfo . streamTracker . addCallSucceeded ( ) ;
@@ -841,8 +871,10 @@ export class Server {
841
871
} catch ( err ) {
842
872
if ( ! call ) {
843
873
call = new Http2ServerCallStream ( stream , null ! , this . options ) ;
844
- this . callTracker . addCallFailed ( ) ;
845
- channelzSessionInfo ?. streamTracker . addCallFailed ( )
874
+ if ( this . channelzEnabled ) {
875
+ this . callTracker . addCallFailed ( ) ;
876
+ channelzSessionInfo ?. streamTracker . addCallFailed ( )
877
+ }
846
878
}
847
879
848
880
if ( err . code === undefined ) {
@@ -860,7 +892,16 @@ export class Server {
860
892
return ;
861
893
}
862
894
863
- const channelzRef = registerChannelzSocket ( session . socket . remoteAddress ?? 'unknown' , this . getChannelzSessionInfoGetter ( session ) ) ;
895
+ let channelzRef : SocketRef ;
896
+ if ( this . channelzEnabled ) {
897
+ channelzRef = registerChannelzSocket ( session . socket . remoteAddress ?? 'unknown' , this . getChannelzSessionInfoGetter ( session ) ) ;
898
+ } else {
899
+ channelzRef = {
900
+ kind : 'socket' ,
901
+ id : - 1 ,
902
+ name : ''
903
+ }
904
+ }
864
905
865
906
const channelzSessionInfo : ChannelzSessionInfo = {
866
907
ref : channelzRef ,
0 commit comments