@@ -323,7 +323,7 @@ export class Client {
323
323
emitter . call = call ;
324
324
let responseMessage : ResponseType | null = null ;
325
325
let receivedStatus = false ;
326
- const callerStackError = new Error ( ) ;
326
+ let callerStackError : Error | null = new Error ( ) ;
327
327
call . start ( callProperties . metadata , {
328
328
onReceiveMetadata : ( metadata ) => {
329
329
emitter . emit ( 'metadata' , metadata ) ;
@@ -342,19 +342,22 @@ export class Client {
342
342
receivedStatus = true ;
343
343
if ( status . code === Status . OK ) {
344
344
if ( responseMessage === null ) {
345
- const callerStack = getErrorStackString ( callerStackError ) ;
345
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
346
346
callProperties . callback ! ( callErrorFromStatus ( {
347
347
code : Status . INTERNAL ,
348
348
details : 'No message received' ,
349
349
metadata : status . metadata
350
- } , callerStack ) ) ;
350
+ } , /* callerStack*/ '' ) ) ;
351
351
} else {
352
352
callProperties . callback ! ( null , responseMessage ) ;
353
353
}
354
354
} else {
355
- const callerStack = getErrorStackString ( callerStackError ) ;
356
- callProperties . callback ! ( callErrorFromStatus ( status , callerStack ) ) ;
355
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
356
+ callProperties . callback ! ( callErrorFromStatus ( status , /* callerStack*/ '' ) ) ;
357
357
}
358
+ /* Avoid retaining the callerStackError object in the call context of
359
+ * the status event handler. */
360
+ callerStackError = null ;
358
361
emitter . emit ( 'status' , status ) ;
359
362
} ,
360
363
} ) ;
@@ -448,7 +451,7 @@ export class Client {
448
451
emitter . call = call ;
449
452
let responseMessage : ResponseType | null = null ;
450
453
let receivedStatus = false ;
451
- const callerStackError = new Error ( ) ;
454
+ let callerStackError : Error | null = new Error ( ) ;
452
455
call . start ( callProperties . metadata , {
453
456
onReceiveMetadata : ( metadata ) => {
454
457
emitter . emit ( 'metadata' , metadata ) ;
@@ -467,7 +470,7 @@ export class Client {
467
470
receivedStatus = true ;
468
471
if ( status . code === Status . OK ) {
469
472
if ( responseMessage === null ) {
470
- const callerStack = getErrorStackString ( callerStackError ) ;
473
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
471
474
callProperties . callback ! ( callErrorFromStatus ( {
472
475
code : Status . INTERNAL ,
473
476
details : 'No message received' ,
@@ -477,9 +480,12 @@ export class Client {
477
480
callProperties . callback ! ( null , responseMessage ) ;
478
481
}
479
482
} else {
480
- const callerStack = getErrorStackString ( callerStackError ) ;
483
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
481
484
callProperties . callback ! ( callErrorFromStatus ( status , callerStack ) ) ;
482
485
}
486
+ /* Avoid retaining the callerStackError object in the call context of
487
+ * the status event handler. */
488
+ callerStackError = null ;
483
489
emitter . emit ( 'status' , status ) ;
484
490
} ,
485
491
} ) ;
@@ -577,7 +583,7 @@ export class Client {
577
583
* call after that. */
578
584
stream . call = call ;
579
585
let receivedStatus = false ;
580
- const callerStackError = new Error ( ) ;
586
+ let callerStackError : Error | null = new Error ( ) ;
581
587
call . start ( callProperties . metadata , {
582
588
onReceiveMetadata ( metadata : Metadata ) {
583
589
stream . emit ( 'metadata' , metadata ) ;
@@ -593,9 +599,12 @@ export class Client {
593
599
receivedStatus = true ;
594
600
stream . push ( null ) ;
595
601
if ( status . code !== Status . OK ) {
596
- const callerStack = getErrorStackString ( callerStackError ) ;
602
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
597
603
stream . emit ( 'error' , callErrorFromStatus ( status , callerStack ) ) ;
598
604
}
605
+ /* Avoid retaining the callerStackError object in the call context of
606
+ * the status event handler. */
607
+ callerStackError = null ;
599
608
stream . emit ( 'status' , status ) ;
600
609
} ,
601
610
} ) ;
@@ -673,7 +682,7 @@ export class Client {
673
682
* call after that. */
674
683
stream . call = call ;
675
684
let receivedStatus = false ;
676
- const callerStackError = new Error ( ) ;
685
+ let callerStackError : Error | null = new Error ( ) ;
677
686
call . start ( callProperties . metadata , {
678
687
onReceiveMetadata ( metadata : Metadata ) {
679
688
stream . emit ( 'metadata' , metadata ) ;
@@ -688,9 +697,12 @@ export class Client {
688
697
receivedStatus = true ;
689
698
stream . push ( null ) ;
690
699
if ( status . code !== Status . OK ) {
691
- const callerStack = getErrorStackString ( callerStackError ) ;
700
+ const callerStack = getErrorStackString ( callerStackError ! ) ;
692
701
stream . emit ( 'error' , callErrorFromStatus ( status , callerStack ) ) ;
693
702
}
703
+ /* Avoid retaining the callerStackError object in the call context of
704
+ * the status event handler. */
705
+ callerStackError = null ;
694
706
stream . emit ( 'status' , status ) ;
695
707
} ,
696
708
} ) ;
0 commit comments