Unverified Commit a328d724 authored by chrisvroberts's avatar chrisvroberts Committed by GitHub

Fix shutdown data race in listner.cc (#761)

A race exists between the runThreaded and shutdown/dtor as follows:

 runThreaded - called
 shutdown - called
 shutdown - check for shutdownFd.isBound returns false (so no notify)
 runThreaded - thread executing 'run' starts
 runThreaded - thread calls shutdownFd.bind
 shutdown - blocks waiting for run thread
 runThreaded - continues to run as no notification received

This deadlock avoided by ensuring the shutdownFd.bind is called before
the thread is created rather than doing it at the start of the thread's
execution.
parent 73f248ac
......@@ -204,7 +204,8 @@ Port Listener::getPort() const {
}
void Listener::run() {
shutdownFd.bind(poller);
if (!shutdownFd.isBound())
shutdownFd.bind(poller);
reactor_.run();
for (;;) {
......@@ -236,6 +237,7 @@ void Listener::run() {
}
void Listener::runThreaded() {
shutdownFd.bind(poller);
acceptThread = std::thread([=]() { this->run(); });
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment