File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ class PerMessageDeflate {
133133    } 
134134
135135    if  ( this . _deflate )  { 
136+       if  ( this . _deflate [ kCallback ] )  { 
137+         this . _deflate [ kCallback ] ( ) ; 
138+       } 
139+ 
136140      this . _deflate . close ( ) ; 
137141      this . _deflate  =  null ; 
138142    } 
@@ -312,7 +316,9 @@ class PerMessageDeflate {
312316    zlibLimiter . push ( ( done )  =>  { 
313317      this . _compress ( data ,  fin ,  ( err ,  result )  =>  { 
314318        done ( ) ; 
315-         callback ( err ,  result ) ; 
319+         if  ( err  ||  result )  { 
320+           callback ( err ,  result ) ; 
321+         } 
316322      } ) ; 
317323    } ) ; 
318324  } 
@@ -419,6 +425,8 @@ class PerMessageDeflate {
419425      this . _deflate . on ( 'data' ,  deflateOnData ) ; 
420426    } 
421427
428+     this . _deflate [ kCallback ]  =  callback ; 
429+ 
422430    this . _deflate . write ( data ) ; 
423431    this . _deflate . flush ( zlib . Z_SYNC_FLUSH ,  ( )  =>  { 
424432      if  ( ! this . _deflate )  { 
@@ -438,6 +446,11 @@ class PerMessageDeflate {
438446
439447      if  ( fin )  data  =  data . slice ( 0 ,  data . length  -  4 ) ; 
440448
449+       // Set callback to null so we won't call it twice if socket is closed 
450+       // (see PerMessageDeflate#cleanup) 
451+       // ideally, we would set it to `null` before calling, but we might set it to null 
452+       this . _deflate [ kCallback ]  =  null ; 
453+ 
441454      if  ( fin  &&  this . params [ `${ endpoint }  ] )  { 
442455        this . _deflate . close ( ) ; 
443456        this . _deflate  =  null ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments