File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,10 @@ class PerMessageDeflate {
133
133
}
134
134
135
135
if ( this . _deflate ) {
136
+ if ( this . _deflate [ kCallback ] ) {
137
+ this . _deflate [ kCallback ] ( ) ;
138
+ }
139
+
136
140
this . _deflate . close ( ) ;
137
141
this . _deflate = null ;
138
142
}
@@ -312,7 +316,9 @@ class PerMessageDeflate {
312
316
zlibLimiter . push ( ( done ) => {
313
317
this . _compress ( data , fin , ( err , result ) => {
314
318
done ( ) ;
315
- callback ( err , result ) ;
319
+ if ( err || result ) {
320
+ callback ( err , result ) ;
321
+ }
316
322
} ) ;
317
323
} ) ;
318
324
}
@@ -419,6 +425,8 @@ class PerMessageDeflate {
419
425
this . _deflate . on ( 'data' , deflateOnData ) ;
420
426
}
421
427
428
+ this . _deflate [ kCallback ] = callback ;
429
+
422
430
this . _deflate . write ( data ) ;
423
431
this . _deflate . flush ( zlib . Z_SYNC_FLUSH , ( ) => {
424
432
if ( ! this . _deflate ) {
@@ -438,6 +446,12 @@ class PerMessageDeflate {
438
446
439
447
if ( fin ) data = data . slice ( 0 , data . length - 4 ) ;
440
448
449
+ //
450
+ // Ensure that the callback will not be called again in
451
+ // `PerMessageDeflate#cleanup()`.
452
+ //
453
+ this . _deflate [ kCallback ] = null ;
454
+
441
455
if ( fin && this . params [ `${ endpoint } _no_context_takeover` ] ) {
442
456
this . _deflate . close ( ) ;
443
457
this . _deflate = null ;
You can’t perform that action at this time.
0 commit comments