Skip to content

Commit cf090c7

Browse files
committed
grpc-js: Fix commitCallWithMostMessages trying to commit completed attempts
1 parent cea545d commit cf090c7

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
@@ -273,15 +273,24 @@ export class RetryingCall implements Call {
273273
}
274274

275275
private commitCallWithMostMessages() {
276+
if (this.state === 'COMMITTED') {
277+
return;
278+
}
276279
let mostMessages = -1;
277280
let callWithMostMessages = -1;
278281
for (const [index, childCall] of this.underlyingCalls.entries()) {
279-
if (childCall.nextMessageToSend > mostMessages) {
282+
if (childCall.state === 'ACTIVE' && childCall.nextMessageToSend > mostMessages) {
280283
mostMessages = childCall.nextMessageToSend;
281284
callWithMostMessages = index;
282285
}
283286
}
284-
this.commitCall(callWithMostMessages);
287+
if (callWithMostMessages === -1) {
288+
/* There are no active calls, disable retries to force the next call that
289+
* is started to be committed. */
290+
this.state = 'TRANSPARENT_ONLY';
291+
} else {
292+
this.commitCall(callWithMostMessages);
293+
}
285294
}
286295

287296
private isStatusCodeInList(list: (Status | string)[], code: Status) {
@@ -601,7 +610,11 @@ export class RetryingCall implements Call {
601610
}
602611
} else {
603612
this.commitCallWithMostMessages();
604-
const call = this.underlyingCalls[this.committedCallIndex!];
613+
// commitCallWithMostMessages can fail if we are between ping attempts
614+
if (this.committedCallIndex === null) {
615+
return;
616+
}
617+
const call = this.underlyingCalls[this.committedCallIndex];
605618
bufferEntry.callback = context.callback;
606619
if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) {
607620
call.call.sendMessageWithContext({

0 commit comments

Comments
 (0)