Retry serverinfo query for adding a PC if the request fails with ServiceUnavailableError. Fixes #88

This commit is contained in:
Cameron Gutman 2018-09-29 03:01:49 -07:00
parent ba7dd31035
commit 4620fa5001
4 changed files with 69 additions and 4 deletions

View file

@ -400,6 +400,8 @@ private:
}
} catch (const GfeHttpResponseException& e) {
emit pairingCompleted(m_Computer, e.toQString());
} catch (const QtNetworkReplyException& e) {
emit pairingCompleted(m_Computer, e.toQString());
}
}
@ -452,6 +454,12 @@ private:
else {
emit quitAppFailed(e.toQString());
}
} catch (const QtNetworkReplyException& e) {
{
QWriteLocker lock(&m_Computer->lock);
m_Computer->pendingQuit = false;
}
emit quitAppFailed(e.toQString());
}
}
@ -534,8 +542,25 @@ private:
qInfo() << "Processing new PC at" << m_Address << "from" << (m_Mdns ? "mDNS" : "user");
QString serverInfo;
try {
// There's a race condition between GameStream servers reporting presence over
// mDNS and the HTTPS server being ready to respond to our queries. To work
// around this issue, we will issue the request again after a few seconds if
// we see a ServiceUnavailableError error.
try {
serverInfo = http.getServerInfo(NvHTTP::NvLogLevel::VERBOSE);
} catch (const QtNetworkReplyException& e) {
if (e.getError() == QNetworkReply::ServiceUnavailableError) {
qWarning() << "Retrying request in 5 seconds after ServiceUnavailableError";
QThread::sleep(5);
serverInfo = http.getServerInfo(NvHTTP::NvLogLevel::VERBOSE);
qInfo() << "Retry successful";
}
else {
// Rethrow other errors
throw e;
}
}
} catch (...) {
if (!m_Mdns) {
emit computerAddCompleted(false);

View file

@ -419,7 +419,7 @@ NvHTTP::openConnection(QUrl baseUrl,
if (logLevel >= NvLogLevel::ERROR) {
qWarning() << command << " request failed with error " << reply->error();
}
GfeHttpResponseException exception(reply->error(), reply->errorString());
QtNetworkReplyException exception(reply->error(), reply->errorString());
delete reply;
throw exception;
}

View file

@ -5,7 +5,8 @@
#include <Limelight.h>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QNetworkAccessManager>
#include <QNetworkReply>
class NvApp
{
@ -52,7 +53,7 @@ public:
}
const char* what() const throw()
const char* what() const
{
return m_StatusMessage.toLatin1();
}
@ -77,6 +78,41 @@ private:
QString m_StatusMessage;
};
class QtNetworkReplyException : public std::exception
{
public:
QtNetworkReplyException(QNetworkReply::NetworkError error, QString errorText) :
m_Error(error),
m_ErrorText(errorText)
{
}
const char* what() const
{
return m_ErrorText.toLatin1();
}
const char* getErrorText() const
{
return m_ErrorText.toLatin1();
}
QNetworkReply::NetworkError getError() const
{
return m_Error;
}
QString toQString() const
{
return m_ErrorText + " (Error " + QString::number(m_Error) + ")";
}
private:
QNetworkReply::NetworkError m_Error;
QString m_ErrorText;
};
class NvHTTP
{
public:

View file

@ -779,6 +779,10 @@ void Session::exec(int displayOriginX, int displayOriginY)
emit displayLaunchError(e.toQString());
s_ActiveSessionSemaphore.release();
return;
} catch (const QtNetworkReplyException& e) {
emit displayLaunchError(e.toQString());
s_ActiveSessionSemaphore.release();
return;
}
SDL_assert(!SDL_WasInit(SDL_INIT_VIDEO));