From 065dcd4d47cf86d385cd76bbe848316e6c57dc87 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Thu, 23 Feb 2023 18:08:23 +0100 Subject: [PATCH] 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. --- .../bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp | 10 ++++++++++ .../bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h | 1 + 2 files changed, 11 insertions(+) diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp index 8e361031..39bd7d5e 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.cpp @@ -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 }); } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h index 9bae4e14..aa69b165 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/GRPC/GRPCClient.h @@ -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.