From 8d19f067fdd0fbecfea1ea87496d5b1266264259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Fri, 21 May 2021 23:25:37 +0200 Subject: [PATCH] M #-: Fix occasional crash on exit (#1242) --- include/MarketPlaceManager.h | 9 +++++++++ src/market/MarketPlaceManagerProtocol.cc | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/include/MarketPlaceManager.h b/include/MarketPlaceManager.h index f51cf6d102..9135df688d 100644 --- a/include/MarketPlaceManager.h +++ b/include/MarketPlaceManager.h @@ -21,6 +21,8 @@ #include "DriverManager.h" #include "Listener.h" +#include + class MarketPlacePool; class MarketPlaceAppPool; class ImagePool; @@ -60,6 +62,8 @@ public: */ void finalize() { + terminate = true; + timer_thread.stop(); DriverManager::stop(drivers_timeout); @@ -167,6 +171,11 @@ private: */ RaftManager * raftm = nullptr; + /** + * Manager is terminating, do not execute any action + */ + std::atomic terminate{false}; + /** * Returns a pointer to the marketplace driver. * @return the marketplace manager driver or 0 in not found diff --git a/src/market/MarketPlaceManagerProtocol.cc b/src/market/MarketPlaceManagerProtocol.cc index e45401669c..3b0ca6c698 100644 --- a/src/market/MarketPlaceManagerProtocol.cc +++ b/src/market/MarketPlaceManagerProtocol.cc @@ -253,6 +253,11 @@ void MarketPlaceManager::_monitor(unique_ptr msg) for (int i=0; i< num; i++) { + if (terminate) + { + return; // Prevent crash on exit, while processing long msg + } + int app_id; int rc = apppool->import(apps[i]->value(), id, name, app_id, err);