From f9c587535035b3a945edcff4ac09ab22ec4dbde2 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 13 Aug 2021 22:45:33 +0300
Subject: [PATCH] SL-15292 waitForChannel crash

This code needs to be turned into a state machine (switch-case between states) with clean exit and each state clean and separate. Right now it passes through all stages on exit and relies onto multiple bools instead of just transitioning to 'exit' state. In some cases coroutine still lives longer than voice singletone, it also needs to be adressed.
---
 indra/newview/llvoicevivox.cpp | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp
index e4d528ece5a..e6da5c59395 100644
--- a/indra/newview/llvoicevivox.cpp
+++ b/indra/newview/llvoicevivox.cpp
@@ -1880,13 +1880,22 @@ bool LLVivoxVoiceClient::waitForChannel()
                 break;
             }
 
-        } while (mVoiceEnabled && !mRelogRequested && !sShuttingDown);
+        } while (!sShuttingDown && mVoiceEnabled && !mRelogRequested);
 
-        LL_DEBUGS("Voice")
-            << "leaving inner waitForChannel loop"
-            << " RelogRequested=" << mRelogRequested
-            << " VoiceEnabled=" << mVoiceEnabled
-            << LL_ENDL;
+        if (!sShuttingDown)
+        {
+            LL_DEBUGS("Voice")
+                << "leaving inner waitForChannel loop"
+                << " RelogRequested=" << mRelogRequested
+                << " VoiceEnabled=" << mVoiceEnabled
+                << LL_ENDL;
+        }
+        else
+        {
+            // if sShuttingDown is set, we already logged out
+            LL_DEBUGS("Voice") << "leaving inner waitForChannel loop." << LL_ENDL;
+            return false;
+        }
 
         mIsProcessingChannels = false;
 
@@ -1902,7 +1911,7 @@ bool LLVivoxVoiceClient::waitForChannel()
                 return false;
             }
         }
-    } while (mVoiceEnabled && mRelogRequested && isGatewayRunning() && !sShuttingDown);
+    } while (!sShuttingDown && mVoiceEnabled && mRelogRequested && isGatewayRunning());
 
     LL_DEBUGS("Voice")
         << "exiting"
-- 
GitLab