diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9503a8ab2f..9de8b3bee6 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -132,6 +132,7 @@ #include #include #include +#include #include #include @@ -139,6 +140,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -1294,6 +1298,32 @@ void GUI_App::shutdown() BOOST_LOG_TRIVIAL(info) << "GUI_App::shutdown exit"; } +void GUI_App::start_exit_watchdog() +{ + // Last resort for code that never returns while the app closes (plugins, vendor libraries, + // network calls). The app config is saved on idle and again in MainFrame::shutdown, so ending + // the process loses little; static destructors and atexit handlers are skipped too, as they may + // be what is stuck. + constexpr auto grace = std::chrono::seconds(30); + try { + // Made now: by the time the watchdog fires, static destruction may be under way. The logger + // holds its own reference, which keeps boost::log's core and sinks alive. + boost::log::sources::severity_logger_mt logger; + std::thread([grace, logger]() mutable { + std::this_thread::sleep_for(grace); + try { + BOOST_LOG_SEV(logger, boost::log::trivial::error) + << "OrcaSlicer did not finish closing within " << grace.count() << " s; ending the process"; + } catch (...) { + // A failing log sink must not stop the exit. + } + std::_Exit(EXIT_FAILURE); + }).detach(); + } catch (const std::system_error& ex) { + BOOST_LOG_TRIVIAL(warning) << "Could not start the exit watchdog: " << ex.what(); + } +} + std::string GUI_App::get_http_url(std::string country_code, std::string path) { diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 4b6e5aa0e3..6838bafcfb 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -435,6 +435,8 @@ public: bool is_closing() const { return m_is_closing.load(std::memory_order_acquire); } void set_closing(bool closing) { m_is_closing.store(closing, std::memory_order_release); } + // Called once closing can no longer be vetoed: ends the process if closing does not finish in time. + void start_exit_watchdog(); // SoftFever bool show_gcode_window() const { return m_show_gcode_window; } diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index f9baeb2a12..9938509e89 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -732,6 +732,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ MarkdownTip::ExitTip(); // Prevent queued selection/UI refresh work from running as normal during reset. wxGetApp().set_closing(true); + wxGetApp().start_exit_watchdog(); m_plater->reset(); this->shutdown();