From 4f2ac8d575549501e29a7c0088293db2e5e236dd Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 19 Dec 2024 11:55:05 -0500 Subject: Prevent deadlock when IPC times out --- src/ipc_state.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ipc_state.cpp b/src/ipc_state.cpp index fca4e59..cba576c 100644 --- a/src/ipc_state.cpp +++ b/src/ipc_state.cpp @@ -191,6 +191,7 @@ struct IPCState { // was unsuccessful, we will grab the mutex after one bad connection // attempt. If the connection was successful, we grab the mutex right // after exiting the loop. + bool show_error = false; { std::lock_guard state_guard(state_mutex); @@ -201,19 +202,25 @@ struct IPCState { should_disconnect = true; address.clear(); - TrackerLog("Giving up on IPC."); SetStatusMessage("Disconnected from game."); - wxMessageBox("Connection to Lingo timed out.", - "Connection failed", wxOK | wxICON_ERROR); - - break; + show_error = true; } else { TrackerLog(fmt::format("Retrying IPC in {} second(s)...", backoff_amount + 1)); } } } + + // We do this after giving up the mutex because otherwise we could + // deadlock with the main thread. + if (show_error) { + TrackerLog("Giving up on IPC."); + + wxMessageBox("Connection to Lingo timed out.", "Connection failed", + wxOK | wxICON_ERROR); + break; + } } // Pretty much every lock guard in the thread is the same. We check for -- cgit 1.4.1