From 17cff5722e376d3a405df0b6b79833cb26c3290f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 21 May 2020 17:10:33 +0200 Subject: [PATCH] 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. --- src/wine-host/bridges/group.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wine-host/bridges/group.cpp b/src/wine-host/bridges/group.cpp index ef5aa6ab..3d573b15 100644 --- a/src/wine-host/bridges/group.cpp +++ b/src/wine-host/bridges/group.cpp @@ -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