diff --git a/src/AsyncWorkQueue.cpp b/src/AsyncWorkQueue.cpp index 91fc2d2d2..be85f5ac2 100644 --- a/src/AsyncWorkQueue.cpp +++ b/src/AsyncWorkQueue.cpp @@ -73,6 +73,18 @@ bool AsyncWorkQueue::removeClientAsyncWrites(client *c) return fFound; } +void AsyncWorkQueue::shutdown() +{ + std::unique_lock lock(m_mutex); + serverAssert(!GlobalLocksAcquired()); + m_fQuitting = true; + m_cvWakeup.notify_all(); + lock.unlock(); + + for (auto &thread : m_vecthreads) + thread.join(); +} + void AsyncWorkQueue::abandonThreads() { std::unique_lock lock(m_mutex); diff --git a/src/AsyncWorkQueue.h b/src/AsyncWorkQueue.h index 2a413404d..1f019324a 100644 --- a/src/AsyncWorkQueue.h +++ b/src/AsyncWorkQueue.h @@ -34,5 +34,7 @@ public: void AddWorkFunction(std::function &&fnAsync, bool fHiPri = false); bool removeClientAsyncWrites(struct client *c); + void shutdown(); + void abandonThreads(); }; \ No newline at end of file diff --git a/src/server.cpp b/src/server.cpp index f5f2a93bd..539295de1 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4225,6 +4225,13 @@ int prepareForShutdown(int flags) { /* Close the listening sockets. Apparently this allows faster restarts. */ closeListeningSockets(1); + if (g_pserver->asyncworkqueue) + { + aeReleaseLock(); + g_pserver->asyncworkqueue->shutdown(); + aeAcquireLock(); + } + for (int iel = 0; iel < cserver.cthreads; ++iel) { aePostFunction(g_pserver->rgthreadvar[iel].el, [iel]{