grpc-js: End calls faster if the deadline has already passed

This commit is contained in:
Michael Lumish 2020-12-02 12:00:19 -08:00
parent 2e3f9ac509
commit 21da990cb0
2 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@grpc/grpc-js", "name": "@grpc/grpc-js",
"version": "1.2.2", "version": "1.2.3",
"description": "gRPC Library for Node - pure JS implementation", "description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/", "homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -56,10 +56,14 @@ export class DeadlineFilter extends BaseFilter implements Filter {
} }
const now: number = new Date().getTime(); const now: number = new Date().getTime();
let timeout = this.deadline - now; let timeout = this.deadline - now;
if (timeout < 0) { if (timeout <= 0) {
timeout = 0; process.nextTick(() => {
} callStream.cancelWithStatus(
if (this.deadline !== Infinity) { Status.DEADLINE_EXCEEDED,
'Deadline exceeded'
);
});
} else if (this.deadline !== Infinity) {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
callStream.cancelWithStatus( callStream.cancelWithStatus(
Status.DEADLINE_EXCEEDED, Status.DEADLINE_EXCEEDED,