File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -501,16 +501,22 @@ export class Http2SubchannelCall implements SubchannelCall {
501
501
sendMessageWithContext ( context : MessageContext , message : Buffer ) {
502
502
this . trace ( 'write() called with message of length ' + message . length ) ;
503
503
const cb : WriteCallback = ( error ?: Error | null ) => {
504
- let code : Status = Status . UNAVAILABLE ;
505
- if (
506
- ( error as NodeJS . ErrnoException ) ?. code === 'ERR_STREAM_WRITE_AFTER_END'
507
- ) {
508
- code = Status . INTERNAL ;
509
- }
510
- if ( error ) {
511
- this . cancelWithStatus ( code , `Write error: ${ error . message } ` ) ;
512
- }
513
- context . callback ?.( ) ;
504
+ /* nextTick here ensures that no stream action can be taken in the call
505
+ * stack of the write callback, in order to hopefully work around
506
+ * https://github.com/nodejs/node/issues/49147 */
507
+ process . nextTick ( ( ) => {
508
+ let code : Status = Status . UNAVAILABLE ;
509
+ if (
510
+ ( error as NodeJS . ErrnoException ) ?. code ===
511
+ 'ERR_STREAM_WRITE_AFTER_END'
512
+ ) {
513
+ code = Status . INTERNAL ;
514
+ }
515
+ if ( error ) {
516
+ this . cancelWithStatus ( code , `Write error: ${ error . message } ` ) ;
517
+ }
518
+ context . callback ?.( ) ;
519
+ } ) ;
514
520
} ;
515
521
this . trace ( 'sending data chunk of length ' + message . length ) ;
516
522
this . callEventTracker . addMessageSent ( ) ;
You can’t perform that action at this time.
0 commit comments