Skip to content

Commit 7ab5368

Browse files
authored
Merge pull request #2349 from murgatroid99/grpc-js_retry_commit_fix
grpc-js: Fix `commitCallWithMostMessages` trying to commit completed attempts
2 parents 2b7f296 + cf090c7 commit 7ab5368

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.8.7",
3+
"version": "1.8.8",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/retrying-call.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,24 @@ export class RetryingCall implements Call {
278278
}
279279

280280
private commitCallWithMostMessages() {
281+
if (this.state === 'COMMITTED') {
282+
return;
283+
}
281284
let mostMessages = -1;
282285
let callWithMostMessages = -1;
283286
for (const [index, childCall] of this.underlyingCalls.entries()) {
284-
if (childCall.nextMessageToSend > mostMessages) {
287+
if (childCall.state === 'ACTIVE' && childCall.nextMessageToSend > mostMessages) {
285288
mostMessages = childCall.nextMessageToSend;
286289
callWithMostMessages = index;
287290
}
288291
}
289-
this.commitCall(callWithMostMessages);
292+
if (callWithMostMessages === -1) {
293+
/* There are no active calls, disable retries to force the next call that
294+
* is started to be committed. */
295+
this.state = 'TRANSPARENT_ONLY';
296+
} else {
297+
this.commitCall(callWithMostMessages);
298+
}
290299
}
291300

292301
private isStatusCodeInList(list: (Status | string)[], code: Status) {
@@ -606,7 +615,11 @@ export class RetryingCall implements Call {
606615
}
607616
} else {
608617
this.commitCallWithMostMessages();
609-
const call = this.underlyingCalls[this.committedCallIndex!];
618+
// commitCallWithMostMessages can fail if we are between ping attempts
619+
if (this.committedCallIndex === null) {
620+
return;
621+
}
622+
const call = this.underlyingCalls[this.committedCallIndex];
610623
bufferEntry.callback = context.callback;
611624
if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) {
612625
call.call.sendMessageWithContext({

0 commit comments

Comments
 (0)