Merge pull request #1648 from murgatroid99/grpc-js_deadline_filter_fast_cancel

grpc-js: End calls faster if the deadline has already passed
This commit is contained in:
Michael Lumish 2021-01-07 12:55:49 -08:00 committed by GitHub
commit 0b026be131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.2.2",
"version": "1.2.3",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"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();
let timeout = this.deadline - now;
if (timeout < 0) {
timeout = 0;
}
if (this.deadline !== Infinity) {
if (timeout <= 0) {
process.nextTick(() => {
callStream.cancelWithStatus(
Status.DEADLINE_EXCEEDED,
'Deadline exceeded'
);
});
} else if (this.deadline !== Infinity) {
this.timer = setTimeout(() => {
callStream.cancelWithStatus(
Status.DEADLINE_EXCEEDED,