Propagate channel closed errors up through waitForReady

The errors thrown by `Channel#getConnectivityState` and `Channel#watchConnectivityState` need to be passed to the callback for `Client#waitForReady`.
This commit is contained in:
Michael Lumish 2018-08-13 11:41:36 -07:00 committed by GitHub
parent db291906fa
commit 6d520c522c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -720,13 +720,23 @@ Client.prototype.waitForReady = function(deadline, callback) {
callback(new Error('Failed to connect before the deadline'));
return;
}
var new_state = self.$channel.getConnectivityState(true);
var new_state;
try {
new_state = self.$channel.getConnectivityState(true);
} catch (e) {
callback(new Error('The channel has been closed'));
return;
}
if (new_state === grpc.connectivityState.READY) {
callback();
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
callback(new Error('Failed to connect to server'));
} else {
self.$channel.watchConnectivityState(new_state, deadline, checkState);
try {
self.$channel.watchConnectivityState(new_state, deadline, checkState);
} catch (e) {
callback(new Error('The channel has been closed'));
}
}
};
/* Force a single round of polling to ensure that the channel state is up