fix(GODT-2393): improved handling of unrecoverable error.

Fix a bug introduced in 265af2d. In the top level exception handler, we may not have add the time to establish connection, so we should not try to use the gRPC service to quit bridge.
This commit is contained in:
Xavier Michelon
2023-02-23 18:08:23 +01:00
parent 00256fafe8
commit 065dcd4d47
2 changed files with 11 additions and 0 deletions

View File

@ -185,6 +185,14 @@ void GRPCClient::connectToServer(QString const &configDir, GRPCConfig const &con
}
//****************************************************************************************************************************************************
/// \return true if the gRPC client is connected to the server.
//****************************************************************************************************************************************************
bool GRPCClient::isConnected() const {
return stub_.get();
}
//****************************************************************************************************************************************************
/// \param[in] clientConfigPath The path to the gRPC client config path.-
/// \param[in] serverToken The token obtained from the server config file.
@ -397,6 +405,8 @@ grpc::Status GRPCClient::setIsDoHEnabled(bool enabled) {
//****************************************************************************************************************************************************
grpc::Status GRPCClient::quit() {
// quitting will shut down the gRPC service, to we may get an 'Unavailable' response for the call
if (!this->isConnected())
return Status::OK; // We're not even connected, we return OK. This maybe be an attempt to do 'a proper' shutdown after an unrecoverable error.
return this->logGRPCCallStatus(stub_->Quit(this->clientContext().get(), empty, &empty), __FUNCTION__, { StatusCode::UNAVAILABLE });
}

View File

@ -60,6 +60,7 @@ public: // member functions.
GRPCClient &operator=(GRPCClient &&) = delete; ///< Disabled move assignment operator.
void setLog(Log *log); ///< Set the log for the client.
void connectToServer(QString const &configDir, GRPCConfig const &config, class ProcessMonitor *serverProcess); ///< Establish connection to the gRPC server.
bool isConnected() const; ///< Check whether the gRPC client is connected to the server.
grpc::Status checkTokens(QString const &clientConfigPath, QString &outReturnedClientToken); ///< Performs a token check.
grpc::Status addLogEntry(Log::Level level, QString const &package, QString const &message); ///< Performs the "AddLogEntry" gRPC call.