From 6d520c522c6c0e4f6acd11609bf7dc60d13f5523 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 13 Aug 2018 11:41:36 -0700 Subject: [PATCH] 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`. --- packages/grpc-native-core/src/client.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/grpc-native-core/src/client.js b/packages/grpc-native-core/src/client.js index 5c293b20..3bf838c3 100644 --- a/packages/grpc-native-core/src/client.js +++ b/packages/grpc-native-core/src/client.js @@ -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