Lock the active plugins map early

To prevent a race condition when an exiting plugin wants to terminate
the process when it think there are no plugins left just as another
yabridge instance is connecting to the group socket.
This commit is contained in:
Robbert van der Helm
2020-05-21 17:10:33 +02:00
parent 8eb01cb519
commit 17cff5722e
+2 -1
View File
@@ -98,6 +98,8 @@ void GroupBridge::accept_requests() {
group_socket_acceptor.async_accept(
[&](const boost::system::error_code& error,
boost::asio::local::stream_protocol::socket socket) {
std::lock_guard lock(active_plugins_mutex);
// Stop the whole process when the socket gets closed unexpectedly
if (error.failed()) {
logger.log("Error while listening for incoming connections:");
@@ -120,7 +122,6 @@ void GroupBridge::accept_requests() {
// Collisions in the generated socket names should be very rare, but
// it could in theory happen
std::lock_guard lock(active_plugins_mutex);
assert(active_plugins.find(parameters) != active_plugins.end());
// CreateThread() doesn't support multiple arguments and requires