Aktualisiere WebSocket-Server und Daemon-Konfiguration
- Ändere die Pfade für SSL-Zertifikate in der Konfigurationsdatei. - Verbessere die Fehlerbehandlung beim Entfernen alter vorbereiteter Anweisungen in HouseWorker. - Füge Debug-Ausgaben zur Nachverfolgung von Verbindungen und Nachrichten im WebSocket-Server hinzu. - Implementiere Timeout-Logik für das Stoppen von Worker- und Watchdog-Threads. - Optimiere die Signalverarbeitung und Shutdown-Logik in main.cpp für bessere Responsivität.
This commit is contained in:
committed by
Torsten (PC)
parent
8fe816dddc
commit
bd961a03d4
34
src/worker.h
34
src/worker.h
@@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <future>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "connection_pool.h"
|
||||
@@ -39,7 +40,16 @@ public:
|
||||
void stopWorkerThread() {
|
||||
runningWorker.store(false);
|
||||
if (workerThread.joinable()) {
|
||||
workerThread.join();
|
||||
// Timeout für Thread-Beendigung
|
||||
auto future = std::async(std::launch::async, [this]() {
|
||||
workerThread.join();
|
||||
});
|
||||
|
||||
if (future.wait_for(std::chrono::milliseconds(500)) == std::future_status::timeout) {
|
||||
std::cerr << "[" << workerName << "] Worker-Thread beendet sich nicht, erzwinge Beendigung..." << std::endl;
|
||||
// Thread wird beim Destruktor automatisch detached
|
||||
workerThread.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +65,15 @@ public:
|
||||
void stopWatchdogThread() {
|
||||
runningWatchdog.store(false);
|
||||
if (watchdogThread.joinable()) {
|
||||
watchdogThread.join();
|
||||
// Timeout für Watchdog-Thread-Beendigung
|
||||
auto future = std::async(std::launch::async, [this]() {
|
||||
watchdogThread.join();
|
||||
});
|
||||
|
||||
if (future.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout) {
|
||||
std::cerr << "[" << workerName << "] Watchdog-Thread beendet sich nicht, erzwinge Beendigung..." << std::endl;
|
||||
watchdogThread.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +93,13 @@ protected:
|
||||
void watchdog() {
|
||||
try {
|
||||
while (runningWatchdog.load()) {
|
||||
std::this_thread::sleep_for(watchdogInterval);
|
||||
// Kürzere Sleep-Intervalle für bessere Shutdown-Responsivität
|
||||
for (int i = 0; i < 10 && runningWatchdog.load(); ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
if (!runningWatchdog.load()) break;
|
||||
|
||||
bool isActive = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(activityMutex);
|
||||
@@ -86,7 +110,9 @@ protected:
|
||||
std::cerr << "[" << workerName << "] Watchdog: Keine Aktivität! Starte Worker neu...\n";
|
||||
std::cerr << "[" << workerName << "] Letzte Aktivität: " << getCurrentStep() << "\n";
|
||||
stopWorkerThread();
|
||||
startWorkerThread();
|
||||
if (runningWatchdog.load()) { // Nur neu starten wenn nicht shutdown
|
||||
startWorkerThread();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
|
||||
Reference in New Issue
Block a user