16
16
*/
17
17
18
18
import * as http2 from 'http2' ;
19
+ import * as util from 'util' ;
19
20
import { AddressInfo } from 'net' ;
20
21
21
22
import { ServiceError } from './call' ;
@@ -89,6 +90,17 @@ interface BindResult {
89
90
90
91
function noop ( ) : void { }
91
92
93
+ /**
94
+ * Decorator to wrap a class method with util.deprecate
95
+ * @param message The message to output if the deprecated method is called
96
+ * @returns
97
+ */
98
+ function deprecate ( message : string ) {
99
+ return function < This , Args extends any [ ] , Return > ( target : ( this : This , ...args : Args ) => Return , context : ClassMethodDecoratorContext < This , ( this : This , ...args : Args ) => Return > ) {
100
+ return util . deprecate ( target , message ) ;
101
+ }
102
+ }
103
+
92
104
function getUnimplementedStatusResponse (
93
105
methodName : string
94
106
) : Partial < ServiceError > {
@@ -160,6 +172,10 @@ export class Server {
160
172
UntypedHandler
161
173
> ( ) ;
162
174
private sessions = new Map < http2 . ServerHttp2Session , ChannelzSessionInfo > ( ) ;
175
+ /**
176
+ * This field only exists to ensure that the start method throws an error if
177
+ * it is called twice, as it did previously.
178
+ */
163
179
private started = false ;
164
180
private options : ChannelOptions ;
165
181
private serverAddressString = 'null' ;
@@ -371,10 +387,6 @@ export class Server {
371
387
creds : ServerCredentials ,
372
388
callback : ( error : Error | null , port : number ) => void
373
389
) : void {
374
- if ( this . started === true ) {
375
- throw new Error ( 'server is already started' ) ;
376
- }
377
-
378
390
if ( typeof port !== 'string' ) {
379
391
throw new TypeError ( 'port must be a string' ) ;
380
392
}
@@ -709,8 +721,6 @@ export class Server {
709
721
}
710
722
}
711
723
712
- this . started = false ;
713
-
714
724
// Always destroy any available sessions. It's possible that one or more
715
725
// tryShutdown() calls are in progress. Don't wait on them to finish.
716
726
this . sessions . forEach ( ( channelzInfo , session ) => {
@@ -750,6 +760,10 @@ export class Server {
750
760
return this . handlers . delete ( name ) ;
751
761
}
752
762
763
+ /**
764
+ * @deprecated No longer needed as of version 1.10.x
765
+ */
766
+ @deprecate ( 'Calling start() is no longer necessary. It can be safely omitted.' )
753
767
start ( ) : void {
754
768
if (
755
769
this . http2ServerList . length === 0 ||
@@ -763,9 +777,6 @@ export class Server {
763
777
if ( this . started === true ) {
764
778
throw new Error ( 'server is already started' ) ;
765
779
}
766
- if ( this . channelzEnabled ) {
767
- this . channelzTrace . addTrace ( 'CT_INFO' , 'Starting' ) ;
768
- }
769
780
this . started = true ;
770
781
}
771
782
@@ -786,9 +797,6 @@ export class Server {
786
797
}
787
798
}
788
799
789
- // Close the server if necessary.
790
- this . started = false ;
791
-
792
800
for ( const { server : http2Server , channelzRef : ref } of this
793
801
. http2ServerList ) {
794
802
if ( http2Server . listening ) {
@@ -1053,10 +1061,6 @@ export class Server {
1053
1061
1054
1062
http2Server . on ( 'stream' , handler . bind ( this ) ) ;
1055
1063
http2Server . on ( 'session' , session => {
1056
- if ( ! this . started ) {
1057
- session . destroy ( ) ;
1058
- return ;
1059
- }
1060
1064
1061
1065
const channelzRef = registerChannelzSocket (
1062
1066
session . socket . remoteAddress ?? 'unknown' ,
0 commit comments