diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-19 11:55:05 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-12-19 11:55:05 -0500 |
commit | 4f2ac8d575549501e29a7c0088293db2e5e236dd (patch) | |
tree | 147361d981ec1721ca5ca129292068a895cf650a /src | |
parent | 69043f73c55cde336eff7f14304e891f1639cbea (diff) | |
download | lingo-ap-tracker-4f2ac8d575549501e29a7c0088293db2e5e236dd.tar.gz lingo-ap-tracker-4f2ac8d575549501e29a7c0088293db2e5e236dd.tar.bz2 lingo-ap-tracker-4f2ac8d575549501e29a7c0088293db2e5e236dd.zip |
Prevent deadlock when IPC times out
Diffstat (limited to 'src')
-rw-r--r-- | src/ipc_state.cpp | 17 |
1 files 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 { | |||
191 | // was unsuccessful, we will grab the mutex after one bad connection | 191 | // was unsuccessful, we will grab the mutex after one bad connection |
192 | // attempt. If the connection was successful, we grab the mutex right | 192 | // attempt. If the connection was successful, we grab the mutex right |
193 | // after exiting the loop. | 193 | // after exiting the loop. |
194 | bool show_error = false; | ||
194 | { | 195 | { |
195 | std::lock_guard state_guard(state_mutex); | 196 | std::lock_guard state_guard(state_mutex); |
196 | 197 | ||
@@ -201,19 +202,25 @@ struct IPCState { | |||
201 | should_disconnect = true; | 202 | should_disconnect = true; |
202 | address.clear(); | 203 | address.clear(); |
203 | 204 | ||
204 | TrackerLog("Giving up on IPC."); | ||
205 | SetStatusMessage("Disconnected from game."); | 205 | SetStatusMessage("Disconnected from game."); |
206 | 206 | ||
207 | wxMessageBox("Connection to Lingo timed out.", | 207 | show_error = true; |
208 | "Connection failed", wxOK | wxICON_ERROR); | ||
209 | |||
210 | break; | ||
211 | } else { | 208 | } else { |
212 | TrackerLog(fmt::format("Retrying IPC in {} second(s)...", | 209 | TrackerLog(fmt::format("Retrying IPC in {} second(s)...", |
213 | backoff_amount + 1)); | 210 | backoff_amount + 1)); |
214 | } | 211 | } |
215 | } | 212 | } |
216 | } | 213 | } |
214 | |||
215 | // We do this after giving up the mutex because otherwise we could | ||
216 | // deadlock with the main thread. | ||
217 | if (show_error) { | ||
218 | TrackerLog("Giving up on IPC."); | ||
219 | |||
220 | wxMessageBox("Connection to Lingo timed out.", "Connection failed", | ||
221 | wxOK | wxICON_ERROR); | ||
222 | break; | ||
223 | } | ||
217 | } | 224 | } |
218 | 225 | ||
219 | // Pretty much every lock guard in the thread is the same. We check for | 226 | // Pretty much every lock guard in the thread is the same. We check for |