mirror of https://github.com/grpc/grpc-node.git
grpc-js: handle http2 backpressure in server
This commit adds backpressure handling code to the ServerWritableStream implementation.
This commit is contained in:
parent
79544366be
commit
a6e2edce9a
|
|
@ -150,16 +150,23 @@ export class ServerWritableStreamImpl<RequestType, ResponseType> extends
|
||||||
this.call.sendMetadata(responseMetadata);
|
this.call.sendMetadata(responseMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _write(chunk: ResponseType, encoding: string, callback: Function) {
|
async _write(
|
||||||
|
chunk: ResponseType, encoding: string,
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
callback: (...args: any[]) => void) {
|
||||||
try {
|
try {
|
||||||
const response = await this.call.serializeMessage(chunk);
|
const response = await this.call.serializeMessage(chunk);
|
||||||
this.call.write(response);
|
|
||||||
|
if (!this.call.write(response)) {
|
||||||
|
this.call.once('drain', callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.code = Status.INTERNAL;
|
err.code = Status.INTERNAL;
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null);
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
_final(callback: Function): void {
|
_final(callback: Function): void {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue