Skip to content

Commit

Permalink
Merge pull request #2349 from murgatroid99/grpc-js_retry_commit_fix
Browse files Browse the repository at this point in the history
grpc-js: Fix `commitCallWithMostMessages` trying to commit completed attempts
  • Loading branch information
murgatroid99 committed Feb 8, 2023
2 parents 2b7f296 + cf090c7 commit 7ab5368
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.8.7",
"version": "1.8.8",
"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
19 changes: 16 additions & 3 deletions packages/grpc-js/src/retrying-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,24 @@ export class RetryingCall implements Call {
}

private commitCallWithMostMessages() {
if (this.state === 'COMMITTED') {
return;
}
let mostMessages = -1;
let callWithMostMessages = -1;
for (const [index, childCall] of this.underlyingCalls.entries()) {
if (childCall.nextMessageToSend > mostMessages) {
if (childCall.state === 'ACTIVE' && childCall.nextMessageToSend > mostMessages) {
mostMessages = childCall.nextMessageToSend;
callWithMostMessages = index;
}
}
this.commitCall(callWithMostMessages);
if (callWithMostMessages === -1) {
/* There are no active calls, disable retries to force the next call that
* is started to be committed. */
this.state = 'TRANSPARENT_ONLY';
} else {
this.commitCall(callWithMostMessages);
}
}

private isStatusCodeInList(list: (Status | string)[], code: Status) {
Expand Down Expand Up @@ -606,7 +615,11 @@ export class RetryingCall implements Call {
}
} else {
this.commitCallWithMostMessages();
const call = this.underlyingCalls[this.committedCallIndex!];
// commitCallWithMostMessages can fail if we are between ping attempts
if (this.committedCallIndex === null) {
return;
}
const call = this.underlyingCalls[this.committedCallIndex];
bufferEntry.callback = context.callback;
if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) {
call.call.sendMessageWithContext({
Expand Down

0 comments on commit 7ab5368

Please sign in to comment.