Skip to content

Commit

Permalink
Merge pull request #1446 from murgatroid99/grpc-js_transient_failure_…
Browse files Browse the repository at this point in the history
…backoff

grpc-js: transition out of TRANSIENT_FAILURE if backoff timer has ended
  • Loading branch information
murgatroid99 committed Jun 3, 2020
2 parents 658961d + ff36a1d commit 8482928
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/grpc-js/src/subchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,25 @@ export class Subchannel {
maxDelay: options['grpc.max_reconnect_backoff_ms'],
};
this.backoffTimeout = new BackoffTimeout(() => {
if (this.continueConnecting) {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.CONNECTING
);
} else {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.IDLE
);
}
this.handleBackoffTimer();
}, backoffOptions);
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
}

private handleBackoffTimer() {
if (this.continueConnecting) {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.CONNECTING
);
} else {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.IDLE
);
}
}

/**
* Start a backoff timer with the current nextBackoff timeout
*/
Expand Down Expand Up @@ -505,6 +509,14 @@ export class Subchannel {
}
this.session = null;
this.stopKeepalivePings();
/* If the backoff timer has already ended by the time we get to the
* TRANSIENT_FAILURE state, we want to immediately transition out of
* TRANSIENT_FAILURE as though the backoff timer is ending right now */
if (!this.backoffTimeout.isRunning()) {
process.nextTick(() => {
this.handleBackoffTimer();
});
}
break;
case ConnectivityState.IDLE:
if (this.session) {
Expand Down

0 comments on commit 8482928

Please sign in to comment.