diff --git a/mainapp.cpp b/mainapp.cpp index 4f7afc9..dd67d28 100644 --- a/mainapp.cpp +++ b/mainapp.cpp @@ -292,7 +292,9 @@ void MainApp::queueRemoveExpiredSessions() void MainApp::waitForWillsQueued() { - while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return !t->allWillsQueued; })) + int i = 0; + + while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return !t->allWillsQueued && t->running; }) && i++ < 5000) { usleep(1000); } @@ -300,7 +302,9 @@ void MainApp::waitForWillsQueued() void MainApp::waitForDisconnectsInitiated() { - while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return !t->allDisconnectsSent; })) + int i = 0; + + while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return !t->allDisconnectsSent && t->running; }) && i++ < 5000) { usleep(1000); } diff --git a/threadloop.cpp b/threadloop.cpp index c3c161d..d577025 100644 --- a/threadloop.cpp +++ b/threadloop.cpp @@ -31,15 +31,17 @@ void do_thread_work(ThreadData *threadData) Logger *logger = Logger::getInstance(); + threadData->running = false; + try { logger->logf(LOG_NOTICE, "Thread %d doing auth init.", threadData->threadnr); threadData->initAuthPlugin(); + threadData->running = true; } catch(std::exception &ex) { logger->logf(LOG_ERR, "Error initializing auth back-end: %s", ex.what()); - threadData->running = false; MainApp *instance = MainApp::getMainApp(); instance->quit(); }