mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2552 from murgatroid99/grpc-js_deferred_write_callback
grpc-js: Defer actions in http2 stream write callback
This commit is contained in:
commit
cd25bada71
|
@ -501,16 +501,22 @@ export class Http2SubchannelCall implements SubchannelCall {
|
||||||
sendMessageWithContext(context: MessageContext, message: Buffer) {
|
sendMessageWithContext(context: MessageContext, message: Buffer) {
|
||||||
this.trace('write() called with message of length ' + message.length);
|
this.trace('write() called with message of length ' + message.length);
|
||||||
const cb: WriteCallback = (error?: Error | null) => {
|
const cb: WriteCallback = (error?: Error | null) => {
|
||||||
let code: Status = Status.UNAVAILABLE;
|
/* nextTick here ensures that no stream action can be taken in the call
|
||||||
if (
|
* stack of the write callback, in order to hopefully work around
|
||||||
(error as NodeJS.ErrnoException)?.code === 'ERR_STREAM_WRITE_AFTER_END'
|
* https://github.com/nodejs/node/issues/49147 */
|
||||||
) {
|
process.nextTick(() => {
|
||||||
code = Status.INTERNAL;
|
let code: Status = Status.UNAVAILABLE;
|
||||||
}
|
if (
|
||||||
if (error) {
|
(error as NodeJS.ErrnoException)?.code ===
|
||||||
this.cancelWithStatus(code, `Write error: ${error.message}`);
|
'ERR_STREAM_WRITE_AFTER_END'
|
||||||
}
|
) {
|
||||||
context.callback?.();
|
code = Status.INTERNAL;
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
this.cancelWithStatus(code, `Write error: ${error.message}`);
|
||||||
|
}
|
||||||
|
context.callback?.();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
this.trace('sending data chunk of length ' + message.length);
|
this.trace('sending data chunk of length ' + message.length);
|
||||||
this.callEventTracker.addMessageSent();
|
this.callEventTracker.addMessageSent();
|
||||||
|
|
Loading…
Reference in New Issue