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,21 +231,25 @@ 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(() => {
if (this.continueConnecting) { this.handleBackoffTimer();
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.CONNECTING
);
} else {
this.transitionToState(
[ConnectivityState.TRANSIENT_FAILURE],
ConnectivityState.IDLE
);
}
}, backoffOptions); }, backoffOptions);
this.subchannelAddressString = subchannelAddressToString(subchannelAddress); 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 * Start a backoff timer with the current nextBackoff timeout
*/ */
@ -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