Skip to content

Commit

Permalink
Merge pull request #1648 from murgatroid99/grpc-js_deadline_filter_fa…
Browse files Browse the repository at this point in the history
…st_cancel

grpc-js: End calls faster if the deadline has already passed
  • Loading branch information
murgatroid99 committed Jan 7, 2021
2 parents fe4bd26 + 21da990 commit 0b026be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -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",
Expand Down
12 changes: 8 additions & 4 deletions packages/grpc-js/src/deadline-filter.ts
Expand Up @@ -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,
Expand Down

0 comments on commit 0b026be

Please sign in to comment.