@@ -223,9 +223,8 @@ class Http2Transport implements Transport {
223
223
) ;
224
224
225
225
session . once ( 'error' , error => {
226
- /* Do nothing here. Any error should also trigger a close event, which is
227
- * where we want to handle that. */
228
226
this . trace ( 'connection closed with error ' + ( error as Error ) . message ) ;
227
+ this . handleDisconnect ( ) ;
229
228
} ) ;
230
229
231
230
if ( logging . isTracerEnabled ( TRACER_NAME ) ) {
@@ -383,6 +382,9 @@ class Http2Transport implements Transport {
383
382
* Handle connection drops, but not GOAWAYs.
384
383
*/
385
384
private handleDisconnect ( ) {
385
+ if ( this . disconnectHandled ) {
386
+ return ;
387
+ }
386
388
this . clearKeepaliveTimeout ( ) ;
387
389
this . reportDisconnectToOwner ( false ) ;
388
390
/* Give calls an event loop cycle to finish naturally before reporting the
@@ -768,6 +770,7 @@ export class Http2SubchannelConnector implements SubchannelConnector {
768
770
) ;
769
771
this . session = session ;
770
772
let errorMessage = 'Failed to connect' ;
773
+ let reportedError = false ;
771
774
session . unref ( ) ;
772
775
session . once ( 'connect' , ( ) => {
773
776
session . removeAllListeners ( ) ;
@@ -778,12 +781,19 @@ export class Http2SubchannelConnector implements SubchannelConnector {
778
781
this . session = null ;
779
782
// Leave time for error event to happen before rejecting
780
783
setImmediate ( ( ) => {
781
- reject ( `${ errorMessage } (${ new Date ( ) . toISOString ( ) } )` ) ;
784
+ if ( ! reportedError ) {
785
+ reportedError = true ;
786
+ reject ( `${ errorMessage } (${ new Date ( ) . toISOString ( ) } )` ) ;
787
+ }
782
788
} ) ;
783
789
} ) ;
784
790
session . once ( 'error' , error => {
785
791
errorMessage = ( error as Error ) . message ;
786
792
this . trace ( 'connection failed with error ' + errorMessage ) ;
793
+ if ( ! reportedError ) {
794
+ reportedError = true ;
795
+ reject ( `${ errorMessage } (${ new Date ( ) . toISOString ( ) } )` ) ;
796
+ }
787
797
} ) ;
788
798
} ) ;
789
799
}
0 commit comments