Commit 210e3b7def9aba0b054f7f3a54023b3099c73d40
1 parent
b4312784
Prevent hangs on quit with buggy plugins
Showing
2 changed files
with
9 additions
and
3 deletions
mainapp.cpp
| ... | ... | @@ -292,7 +292,9 @@ void MainApp::queueRemoveExpiredSessions() |
| 292 | 292 | |
| 293 | 293 | void MainApp::waitForWillsQueued() |
| 294 | 294 | { |
| 295 | - while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr<ThreadData> t){ return !t->allWillsQueued; })) | |
| 295 | + int i = 0; | |
| 296 | + | |
| 297 | + while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr<ThreadData> t){ return !t->allWillsQueued && t->running; }) && i++ < 5000) | |
| 296 | 298 | { |
| 297 | 299 | usleep(1000); |
| 298 | 300 | } |
| ... | ... | @@ -300,7 +302,9 @@ void MainApp::waitForWillsQueued() |
| 300 | 302 | |
| 301 | 303 | void MainApp::waitForDisconnectsInitiated() |
| 302 | 304 | { |
| 303 | - while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr<ThreadData> t){ return !t->allDisconnectsSent; })) | |
| 305 | + int i = 0; | |
| 306 | + | |
| 307 | + while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr<ThreadData> t){ return !t->allDisconnectsSent && t->running; }) && i++ < 5000) | |
| 304 | 308 | { |
| 305 | 309 | usleep(1000); |
| 306 | 310 | } | ... | ... |
threadloop.cpp
| ... | ... | @@ -31,15 +31,17 @@ void do_thread_work(ThreadData *threadData) |
| 31 | 31 | |
| 32 | 32 | Logger *logger = Logger::getInstance(); |
| 33 | 33 | |
| 34 | + threadData->running = false; | |
| 35 | + | |
| 34 | 36 | try |
| 35 | 37 | { |
| 36 | 38 | logger->logf(LOG_NOTICE, "Thread %d doing auth init.", threadData->threadnr); |
| 37 | 39 | threadData->initAuthPlugin(); |
| 40 | + threadData->running = true; | |
| 38 | 41 | } |
| 39 | 42 | catch(std::exception &ex) |
| 40 | 43 | { |
| 41 | 44 | logger->logf(LOG_ERR, "Error initializing auth back-end: %s", ex.what()); |
| 42 | - threadData->running = false; | |
| 43 | 45 | MainApp *instance = MainApp::getMainApp(); |
| 44 | 46 | instance->quit(); |
| 45 | 47 | } | ... | ... |