From c75bfc618a8e3ce9ed0a430d1cbc32b35b73767c Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 26 Oct 2026 22:07:39 +0100 Subject: [PATCH] Honor core stop in desktop owner loop and verify cleanup --- tools/chatgui/tests/test_utun_node.cpp | 16 ++++++++++++++++ tools/chatgui/transport/utun_node.cpp | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/chatgui/tests/test_utun_node.cpp b/tools/chatgui/tests/test_utun_node.cpp index f158be60..ad96927a 100644 --- a/tools/chatgui/tests/test_utun_node.cpp +++ b/tools/chatgui/tests/test_utun_node.cpp @@ -91,6 +91,22 @@ private slots: } } + void coreStopFinishesOwnerThread() { + QTemporaryDir directory; QVERIFY(directory.isValid()); + const QString path = directory.filePath("node.cfg"); + QFile config(path); QVERIFY(config.open(QIODevice::WriteOnly)); + const QByteArray text = "[global]\n" + identity + "[chatserver]\ngroup_autoconnect=0\nstorage_autoload=0\n[ntp]\nenabled=no\n"; + QCOMPARE(config.write(text), text.size()); config.close(); + UtunNode node; + node.setDbPath(directory.filePath("db")); node.setDebugFile(directory.filePath("node.log")); + QSignalSpy stopped(&node, &UtunNode::stopped); + QVERIFY(node.start(path)); + gui_bridge_post_uasync_fn([](void*) { utun_instance_stop(gui_bridge_get_inst()); }, nullptr); + QTRY_COMPARE_WITH_TIMEOUT(stopped.count(), 1, 3000); + node.stop(); + QVERIFY(!node.isRunning() && !node.instance() && !gui_bridge_get_inst() && !gui_bridge_is_uasync_ready()); + } + void tunFailureRejectsStartup() { QTemporaryDir directory; QVERIFY(directory.isValid()); const QString path = directory.filePath("node.cfg"); diff --git a/tools/chatgui/transport/utun_node.cpp b/tools/chatgui/transport/utun_node.cpp index 0575edc6..8baefa2c 100644 --- a/tools/chatgui/transport/utun_node.cpp +++ b/tools/chatgui/transport/utun_node.cpp @@ -279,9 +279,10 @@ void UtunNode::runLoop(std::promise startup) { cfg->global.tun_enabled, cfg->global.tun_ifname); startup.set_value(QString()); - while (!m_stop) { + while (!m_stop && m_instance->running) { uasync_poll(ua, 100); } + if (!m_stop) DEBUG_ERROR(DEBUG_CATEGORY_SYS, "desktop core requested stop; releasing services outside callbacks"); gui_bridge_set_inst(nullptr); uasync_mark_stopped(ua);