From 6a20679c683f8da7888e7569a6e3f96eb6ba7a15 Mon Sep 17 00:00:00 2001
From: Rider Linden <rider@lindenlab.com>
Date: Thu, 3 Mar 2016 11:56:19 -0800
Subject: [PATCH] MAINT-5693: Make COF Version from AIS authoritive.  Ask until
 we get it.

---
 indra/newview/llappearancemgr.cpp | 35 ++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index a2ab32a09eb..99dcb80a4a1 100755
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -3419,20 +3419,25 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
     // Actually send the request.
     LL_DEBUGS("Avatar") << "Will send request for cof_version " << cofVersion << LL_ENDL;
 
-//         LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter(
-//             "UpdateAvatarAppearance", gAgent.getAgentPolicy()));
-
-    S32 reqCofVersion = cofVersion;
-    if (gSavedSettings.getBOOL("DebugForceAppearanceRequestFailure"))
-    {
-        reqCofVersion += 999;
-        LL_WARNS("Avatar") << "Forcing version failure on COF Baking" << LL_ENDL;
-    }
+//  LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter(
+//      "UpdateAvatarAppearance", gAgent.getAgentPolicy()));
 
+    bool bRetry;
     do
     {
+        bRetry = false;
         LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest());
 
+        S32 reqCofVersion = getCOFVersion();  // Treat COF version (gets set by AISAPI as authoritative, 
+                                                // not what the bake request tells us to use).
+        if (gSavedSettings.getBOOL("DebugForceAppearanceRequestFailure"))
+        {
+            reqCofVersion += 999;
+            LL_WARNS("Avatar") << "Forcing version failure on COF Baking" << LL_ENDL;
+        }
+
+        LL_INFOS() << "Requesting bake for COF version " << reqCofVersion << LL_ENDL;
+
         LLSD postData;
         if (gSavedSettings.getBOOL("DebugAvatarExperimentalServerAppearanceUpdate"))
         {
@@ -3461,13 +3466,14 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
             // on multiple machines.
             if (result.has("expected"))
             {
-                reqCofVersion = result["expected"].asInteger();
+                S32 expectedCofVersion = result["expected"].asInteger();
+                bRetry = true;
+                // Wait for a 1/2 second before trying again.  Just to keep from asking too quickly.
+                llcoro::suspendUntilTimeout(0.5);
 
-                LL_WARNS("Avatar") << "Will Retry with expected COF value of " << reqCofVersion << LL_ENDL;
+                LL_WARNS("Avatar") << "Server expected " << expectedCofVersion << " as COF version" << LL_ENDL;
                 continue;
             }
-
-            break;
         }
 
         LL_DEBUGS("Avatar") << "succeeded" << LL_ENDL;
@@ -3476,8 +3482,7 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
             dump_sequential_xml(gAgentAvatarp->getFullname() + "_appearance_request_ok", result);
         }
 
-        break;
-    } while (true);
+    } while (bRetry);
 
 #if 0
     LL_WARNS("Avatar") << "END: Server Bake request #" << r_count << "!" << LL_ENDL;
-- 
GitLab