From cd644cc8513f0a347c776d1740b80d1f7304ae86 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Jan 2022 18:56:49 +0100 Subject: [PATCH] added preventive removal of ipc channel --- src/gui/qt-daemon/application/mainwindow.cpp | 19 +++++++++++++++++-- src/gui/qt-daemon/application/mainwindow.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 0c0ce687..445acb10 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -744,11 +744,25 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c } } +bool MainWindow::remove_ipc() +{ + try { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + } + catch (...) + { + } + return true; +} bool MainWindow::init_ipc_server() { + //in case previous instance wasn't close graceful, ipc channel will remain open and new creation will fail, so we + //trying to close it anyway before open, to make sure there are no dead channels. If there are another running instance, it wom't + //let channel to close, so it will fail later on creating channel + remove_ipc(); #define GUI_IPC_BUFFER_SIZE 10000 try { //Create a message queue. @@ -775,18 +789,19 @@ bool MainWindow::init_ipc_server() handle_ipc_event(buff);//todo process token } } - boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + remove_ipc(); LOG_PRINT_L0("IPC Handling thread finished"); } catch (const std::exception& ex) { + remove_ipc(); boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); LOG_ERROR("Failed to receive IPC que: " << ex.what()); } catch (...) { - boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + remove_ipc(); LOG_ERROR("Failed to receive IPC que: unknown exception"); } }); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 974b0bea..4f7af71d 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -240,6 +240,7 @@ private: bool load_app_config(); bool init_window(); bool init_ipc_server(); + bool remove_ipc(); std::string get_wallet_log_prefix(size_t wallet_id) const { return m_backend.get_wallet_log_prefix(wallet_id); }