@@ -19,6 +19,16 @@ module.exports = function (dependencies) {
19
19
20
20
function Client ( options ) {
21
21
this . config = config ( options ) ;
22
+ this . healthCheckInterval = setInterval ( ( ) => {
23
+ if ( this . session && ! this . session . destroyed ) {
24
+ this . session . ping ( ( error , duration ) => {
25
+ if ( error ) {
26
+ logger ( "No Ping response after " + duration + " ms" ) ;
27
+ }
28
+ logger ( "Ping response after " + duration + " ms" ) ;
29
+ } )
30
+ }
31
+ } , this . config . heartBeat ) . unref ( ) ;
22
32
}
23
33
24
34
Client . prototype . write = function write ( notification , device , count ) {
@@ -43,6 +53,16 @@ module.exports = function (dependencies) {
43
53
}
44
54
} ) ;
45
55
56
+ this . session . on ( "goaway" , ( errorCode , lastStreamId , opaqueData ) => {
57
+ logger ( `GOAWAY received: (errorCode ${ errorCode } , lastStreamId: ${ lastStreamId } , opaqueData: ${ opaqueData } )` ) ;
58
+ // gracefully stop accepting new streams
59
+ if ( this . session && ! this . session . destroyed ) {
60
+ this . session . close ( ( ) => {
61
+ this . session . destroy ( ) ;
62
+ } ) ;
63
+ }
64
+ } ) ;
65
+
46
66
if ( logger . enabled ) {
47
67
this . session . on ( "connect" , ( ) => {
48
68
logger ( "Session connected" ) ;
@@ -53,9 +73,6 @@ module.exports = function (dependencies) {
53
73
this . session . on ( "frameError" , ( frameType , errorCode , streamId ) => {
54
74
logger ( `Frame error: (frameType: ${ frameType } , errorCode ${ errorCode } , streamId: ${ streamId } )` ) ;
55
75
} ) ;
56
- this . session . on ( "goaway" , ( errorCode , lastStreamId , opaqueData ) => {
57
- logger ( `GOAWAY received: (errorCode ${ errorCode } , lastStreamId: ${ lastStreamId } , opaqueData: ${ opaqueData } )` ) ;
58
- } ) ;
59
76
}
60
77
}
61
78
@@ -140,6 +157,9 @@ module.exports = function (dependencies) {
140
157
} ;
141
158
142
159
Client . prototype . shutdown = function shutdown ( callback ) {
160
+ if ( this . healthCheckInterval ) {
161
+ clearInterval ( this . healthCheckInterval ) ;
162
+ }
143
163
if ( this . session && ! this . session . destroyed ) {
144
164
this . session . shutdown ( { graceful : true } , ( ) => {
145
165
this . session . destroy ( ) ;
0 commit comments