mirror of https://github.com/grpc/grpc-node.git
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:
parent
db291906fa
commit
6d520c522c
|
|
@ -720,13 +720,23 @@ Client.prototype.waitForReady = function(deadline, callback) {
|
||||||
callback(new Error('Failed to connect before the deadline'));
|
callback(new Error('Failed to connect before the deadline'));
|
||||||
return;
|
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) {
|
if (new_state === grpc.connectivityState.READY) {
|
||||||
callback();
|
callback();
|
||||||
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
|
} else if (new_state === grpc.connectivityState.FATAL_FAILURE) {
|
||||||
callback(new Error('Failed to connect to server'));
|
callback(new Error('Failed to connect to server'));
|
||||||
} else {
|
} 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
|
/* Force a single round of polling to ensure that the channel state is up
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue