grpc-js: transition out of TRANSIENT_FAILURE if backoff timer has ended

This commit is contained in:
Michael Lumish 2020-05-27 10:21:42 -07:00
parent 075a75b015
commit ff36a1de07
1 changed files with 23 additions and 11 deletions

View File

@ -231,6 +231,12 @@ export class Subchannel {
maxDelay: options['grpc.max_reconnect_backoff_ms'], maxDelay: options['grpc.max_reconnect_backoff_ms'],
}; };
this.backoffTimeout = new BackoffTimeout(() => { this.backoffTimeout = new BackoffTimeout(() => {
this.handleBackoffTimer();
}, backoffOptions);
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
}
private handleBackoffTimer() {
if (this.continueConnecting) { if (this.continueConnecting) {
this.transitionToState( this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE], [ConnectivityState.TRANSIENT_FAILURE],
@ -242,8 +248,6 @@ export class Subchannel {
ConnectivityState.IDLE ConnectivityState.IDLE
); );
} }
}, backoffOptions);
this.subchannelAddressString = subchannelAddressToString(subchannelAddress);
} }
/** /**
@ -505,6 +509,14 @@ export class Subchannel {
} }
this.session = null; this.session = null;
this.stopKeepalivePings(); 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; break;
case ConnectivityState.IDLE: case ConnectivityState.IDLE:
/* Stopping the backoff timer here is probably redundant because we /* Stopping the backoff timer here is probably redundant because we