From 6da1909d4b20be64b4999d3c5f698dd5eedc8456 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 22 May 2020 22:50:29 +0200 Subject: [PATCH] Fix interleaved group host initialization In case two yabridge instances start at the same time and both try to launch a group host for the same group and the second plugin connects to the first group host, then we should of course be using that process'es PID to check if the group host is still running. --- src/plugin/plugin-bridge.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugin/plugin-bridge.cpp b/src/plugin/plugin-bridge.cpp index 4d976ef4..0bafc39f 100644 --- a/src/plugin/plugin-bridge.cpp +++ b/src/plugin/plugin-bridge.cpp @@ -720,6 +720,8 @@ void PluginBridge::launch_vst_host() { // TODO: Replace this polling with inotify when encapsulating // the different host launch behaviors while (vst_host.running()) { + std::this_thread::sleep_for(20ms); + try { // This is the exact same connection sequence as above boost::asio::local::stream_protocol::socket group_socket( @@ -729,11 +731,14 @@ void PluginBridge::launch_vst_host() { write_object(group_socket, GroupRequest{plugin_path.string(), socket_path.string()}); - read_object(group_socket); + const auto response = + read_object(group_socket); + // If two group processes started at the same time, than the + // first one will be the one to respond to the host request + vst_host_pid = response.pid; return; } catch (const boost::system::system_error&) { - std::this_thread::sleep_for(20ms); } } });