diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 5e0de2959aa..447cfc15bee 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -256,10 +256,7 @@ PHP_METHOD(Channel, watchConnectivityState) { grpc_event event = grpc_completion_queue_pluck( completion_queue, NULL, gpr_inf_future(GPR_CLOCK_REALTIME)); - if (!event.success) { - RETURN_BOOL(0); - } - RETURN_BOOL(1); + RETURN_BOOL(event.success); } /** diff --git a/src/php/lib/Grpc/BaseStub.php b/src/php/lib/Grpc/BaseStub.php index dc507df92cf..9d6a77b8553 100755 --- a/src/php/lib/Grpc/BaseStub.php +++ b/src/php/lib/Grpc/BaseStub.php @@ -85,8 +85,9 @@ class BaseStub { /** * @param $timeout in microseconds * @return bool true if channel is ready + * @throw Exception if channel is in FATAL_ERROR state */ - public function watchForReady($timeout) { + public function waitForReady($timeout) { $new_state = $this->getConnectivityState(true); if ($this->_checkConnectivityState($new_state)) { return true; @@ -96,14 +97,16 @@ class BaseStub { $delta = new Timeval($timeout); $deadline = $now->add($delta); - if (!$this->channel->watchConnectivityState($new_state, $deadline)) { - return false; + while ($this->channel->watchConnectivityState($new_state, $deadline)) { + // state has changed before deadline + $new_state = $this->getConnectivityState(); + if ($this->_checkConnectivityState($new_state)) { + return true; + } } + // deadline has passed $new_state = $this->getConnectivityState(); - if ($this->_checkConnectivityState($new_state)) { - return true; - } - return false; + return $this->_checkConnectivityState($new_state); } private function _checkConnectivityState($new_state) {