Fix network listener shutdown
Reviewers: mculinovic, buda Reviewed By: mculinovic Subscribers: teon.banek, pullbot Differential Revision: https://phabricator.memgraph.io/D1603
This commit is contained in:
parent
6682f174f1
commit
4a81ad6e46
src/communication
@ -85,11 +85,8 @@ class Listener final {
|
||||
}
|
||||
|
||||
~Listener() {
|
||||
alive_.store(false);
|
||||
if (timeout_thread_.joinable()) timeout_thread_.join();
|
||||
for (auto &worker_thread : worker_threads_) {
|
||||
worker_thread.join();
|
||||
}
|
||||
Shutdown();
|
||||
AwaitShutdown();
|
||||
}
|
||||
|
||||
Listener(const Listener &) = delete;
|
||||
@ -122,6 +119,22 @@ class Listener final {
|
||||
sessions_.back().get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function starts a graceful shutdown of the listener.
|
||||
*/
|
||||
void Shutdown() { alive_.store(false); }
|
||||
|
||||
/**
|
||||
* This function blocks the calling thread until the listener shutdown is
|
||||
* complete.
|
||||
*/
|
||||
void AwaitShutdown() {
|
||||
if (timeout_thread_.joinable()) timeout_thread_.join();
|
||||
for (auto &worker_thread : worker_threads_) {
|
||||
if (worker_thread.joinable()) worker_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* This function polls the event queue and processes incoming data.
|
||||
|
@ -98,11 +98,14 @@ class Server final {
|
||||
alive_.store(false);
|
||||
// Shutdown the socket to return from any waiting `Accept` calls.
|
||||
socket_.Shutdown();
|
||||
// Shutdown the listener.
|
||||
listener_.Shutdown();
|
||||
}
|
||||
|
||||
/// Waits for the server to be signaled to shutdown
|
||||
void AwaitShutdown() {
|
||||
if (thread_.joinable()) thread_.join();
|
||||
listener_.AwaitShutdown();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user