Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

xCloud login: six tries over ~25 s (a 502 lasted longer than four)

Rafael Abud Ferreira24c3b760b8f4
diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cpp
index 60d975d..4f14a2c 100644
--- a/src/xcloud/gssv.cpp
+++ b/src/xcloud/gssv.cpp
@@ -9,6 +9,7 @@
#include "util/log.h"
#include "xcloud/catalog.h"
+#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
@@ -18,7 +19,7 @@ namespace xc::xcloud {
namespace {
constexpr const char* kClientHeader = "XboxComBrowser";
-constexpr int kLoginTries = 4; // xCloud login: tries on a 5xx / no answer
+constexpr int kLoginTries = 6; // xCloud login: tries on a 5xx / no answer
// Sent like the Windows Xbox app does: "Windows" plus a 1080p display is what
// gets a 1080p stream; an Android device with a 720p display gets 720p.
@@ -272,7 +273,7 @@ bool GssvClient::login(const auth::XblToken& gssvXsts, std::string& err) {
XC_LOGI("xCloud login as country %s", loginCountry_.c_str()); // not the address
}
// The service fails now and then with a 5xx (or is slow to answer) and
- // works on the next try: up to four tries, 1, 2 and 4 s apart. A refusal
+ // works a little later: up to six tries, 1, 2, 4, 8 and 8 s apart. A refusal
// (4xx) is an answer, not tried again.
net::Response r;
std::optional<json::Value> j;
@@ -283,7 +284,7 @@ bool GssvClient::login(const auth::XblToken& gssvXsts, std::string& err) {
bool transient = r.status == 0 || r.status == 408 || r.status == 429 || r.status >= 500;
if (!transient || attempt == kLoginTries) break;
XC_LOGW("xCloud login: %s, trying again (%d/%d)", describe(r).c_str(), attempt + 1, kLoginTries);
- platform::sleepMs(1000u << (attempt - 1));
+ platform::sleepMs(1000u << std::min(attempt - 1, 3));
}
loginStatus_ = r.status;
if (!r.ok() || !j || !(*j)["gsToken"].isString()) {
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index ebf6be0..d10556f 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -919,7 +919,7 @@ static void testLoginRetry() {
});
xcloud::GssvClient gssv;
std::string err;
- CHECK(gssv.login(auth::XblToken{}, err) && calls == 3);
+ CHECK(gssv.login(auth::XblToken{}, err) && calls == 3); // (3 s of waits)
calls = 0;
net::setTestTransport([&](const net::Request&) {
++calls;