@@ -377,6 +377,8 @@ function onFrameError(id, type, code) {
377
377
function emitGoaway ( state , code , lastStreamID , buf ) {
378
378
this . emit ( 'goaway' , code , lastStreamID , buf ) ;
379
379
// Tear down the session or destroy
380
+ if ( state . destroying || state . destroyed )
381
+ return ;
380
382
if ( ! state . shuttingDown && ! state . shutdown ) {
381
383
this . shutdown ( { } , this . destroy . bind ( this ) ) ;
382
384
} else {
@@ -970,7 +972,7 @@ class Http2Session extends EventEmitter {
970
972
state . destroying = true ;
971
973
972
974
// Unenroll the timer
973
- unenroll ( this ) ;
975
+ this . setTimeout ( 0 ) ;
974
976
975
977
// Shut down any still open streams
976
978
const streams = state . streams ;
@@ -1530,7 +1532,7 @@ class Http2Stream extends Duplex {
1530
1532
session . removeListener ( 'close' , this [ kState ] . closeHandler ) ;
1531
1533
1532
1534
// Unenroll the timer
1533
- unenroll ( this ) ;
1535
+ this . setTimeout ( 0 ) ;
1534
1536
1535
1537
setImmediate ( finishStreamDestroy . bind ( this , handle ) ) ;
1536
1538
@@ -2180,7 +2182,7 @@ function socketDestroy(error) {
2180
2182
const type = this [ kSession ] [ kType ] ;
2181
2183
debug ( `[${ sessionName ( type ) } ] socket destroy called` ) ;
2182
2184
delete this [ kServer ] ;
2183
- this . removeListener ( 'timeout' , socketOnTimeout ) ;
2185
+ this . setTimeout ( 0 ) ;
2184
2186
// destroy the session first so that it will stop trying to
2185
2187
// send data while we close the socket.
2186
2188
this [ kSession ] . destroy ( ) ;
@@ -2249,10 +2251,13 @@ function socketOnTimeout() {
2249
2251
process . nextTick ( ( ) => {
2250
2252
const server = this [ kServer ] ;
2251
2253
const session = this [ kSession ] ;
2252
- // If server or session are undefined, then we're already in the process of
2253
- // shutting down, do nothing.
2254
+ // If server or session are undefined, or session.destroyed is true
2255
+ // then we're already in the process of shutting down, do nothing.
2254
2256
if ( server === undefined || session === undefined )
2255
2257
return ;
2258
+ const state = session [ kState ] ;
2259
+ if ( state . destroyed || state . destroying )
2260
+ return ;
2256
2261
if ( ! server . emit ( 'timeout' , session , this ) ) {
2257
2262
session . shutdown (
2258
2263
{
0 commit comments