-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.3 Musicbrainz fixes #10875
2.3 Musicbrainz fixes #10875
Changes from 8 commits
04bbef6
2d78c63
48d0378
a75d93f
ad3172d
404d308
ef94bb0
41abb4d
7ba6ae4
498e828
86f4c07
1e34da3
a29fa94
9f69b96
ba501bc
7c388fa
8b1fffc
10326bc
e53c558
a4d8b70
eb217e9
ec09754
bb21444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,32 +123,24 @@ void WebTask::onNetworkError( | |
QNetworkReply::NetworkError errorCode, | ||
const QString& errorString, | ||
const WebResponseWithContent& responseWithContent) { | ||
DEBUG_ASSERT(m_state == State::Pending); | ||
DEBUG_ASSERT(m_state == State::Failed || m_state == State::Pending); | ||
DEBUG_ASSERT(m_timeoutTimerId == kInvalidTimerId); | ||
|
||
DEBUG_ASSERT(errorCode != QNetworkReply::NoError); | ||
switch (errorCode) { | ||
case QNetworkReply::OperationCanceledError: | ||
// Client-side abort or timeout | ||
m_state = State::Aborted; | ||
break; | ||
case QNetworkReply::TimeoutError: | ||
// Network or server-side timeout | ||
case QNetworkReply::OperationCanceledError: // Client-side timeout | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client- and server-side abort should be distinguished. Why did you merge them? The state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are here in onNetworkError() this is only called if a start request fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Writing code is easier than fruitless arguing and explaining. Override |
||
case QNetworkReply::TimeoutError: // Network or server-side timeout | ||
m_state = State::TimedOut; | ||
break; | ||
default: | ||
m_state = State::Failed; | ||
} | ||
DEBUG_ASSERT(hasTerminated()); | ||
|
||
if (m_state == State::Aborted) { | ||
emitAborted(responseWithContent.requestUrl()); | ||
} else { | ||
emitNetworkError( | ||
errorCode, | ||
errorString, | ||
responseWithContent); | ||
} | ||
emitNetworkError( | ||
errorCode, | ||
errorString, | ||
responseWithContent); | ||
} | ||
|
||
void WebTask::emitNetworkError( | ||
|
@@ -183,7 +175,6 @@ void WebTask::slotStart(int timeoutMillis, int delayMillis) { | |
// Reset state | ||
DEBUG_ASSERT(!m_pendingNetworkReplyWeakPtr); | ||
DEBUG_ASSERT(m_timeoutTimerId == kInvalidTimerId); | ||
m_state = State::Initial; | ||
m_timeoutMillis = kNoTimeout; | ||
|
||
if (delayMillis > 0) { | ||
|
@@ -205,7 +196,7 @@ void WebTask::slotStart(int timeoutMillis, int delayMillis) { | |
|
||
auto* const pNetworkAccessManager = m_networkAccessManagerWeakPtr.data(); | ||
VERIFY_OR_DEBUG_ASSERT(pNetworkAccessManager) { | ||
m_state = State::Pending; | ||
m_state = State::Failed; | ||
onNetworkError( | ||
QNetworkReply::NetworkSessionFailedError, | ||
tr("No network access"), | ||
|
@@ -222,18 +213,12 @@ void WebTask::slotStart(int timeoutMillis, int delayMillis) { | |
m_pendingNetworkReplyWeakPtr = doStartNetworkRequest( | ||
pNetworkAccessManager, | ||
timeoutMillis); | ||
// Still idle, because we are in the same thread. | ||
// The derived class is not allowed to abort a request | ||
// during the callback before it has beeen started | ||
// successfully. Instead it should return nullptr | ||
// to abort the task immediately. | ||
DEBUG_ASSERT(m_state == State::Initial); | ||
if (!m_pendingNetworkReplyWeakPtr) { | ||
kLogger.debug() | ||
<< this | ||
<< "Network request has not been started"; | ||
m_state = State::Aborted; | ||
emitAborted(/*request URL is unknown*/); | ||
m_state = State::Failed; | ||
onNetworkError( | ||
QNetworkReply::NetworkSessionFailedError, | ||
tr("Request URL issue, network request has not been started"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could you be sure that this only happens for invalid URLs? Derived classes may return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will change the message accordingly. |
||
WebResponseWithContent{}); | ||
return; | ||
} | ||
|
||
|
@@ -263,7 +248,7 @@ void WebTask::slotAbort() { | |
if (m_state == State::Initial) { | ||
kLogger.debug() | ||
<< this | ||
<< "Cannot abort idle task"; | ||
<< "Cannot abort task in Initial state"; | ||
} else { | ||
DEBUG_ASSERT(hasTerminated()); | ||
kLogger.debug() | ||
|
@@ -403,27 +388,35 @@ void WebTask::slotNetworkReplyFinished() { | |
m_timeoutTimerId = kInvalidTimerId; | ||
} | ||
|
||
const auto statusCode = readStatusCode(*pFinishedNetworkReply); | ||
const HttpStatusCode statusCode = readStatusCode(*pFinishedNetworkReply); | ||
if (pFinishedNetworkReply->error() != QNetworkReply::NetworkError::NoError) { | ||
onNetworkError( | ||
pFinishedNetworkReply->error(), | ||
pFinishedNetworkReply->errorString(), | ||
WebResponseWithContent{ | ||
WebResponse{ | ||
pFinishedNetworkReply->url(), | ||
pFinishedNetworkReply->request().url(), | ||
statusCode}, | ||
readContentType(*pFinishedNetworkReply), | ||
readContentData(pFinishedNetworkReply).value_or(QByteArray{}), | ||
}); | ||
DEBUG_ASSERT(hasTerminated()); | ||
m_state = State::Failed; | ||
doNetworkError(pFinishedNetworkReply, statusCode); | ||
return; | ||
} | ||
|
||
m_state = State::Finished; | ||
doNetworkReplyFinished(pFinishedNetworkReply, statusCode); | ||
} | ||
|
||
void WebTask::doNetworkError( | ||
QNetworkReply* pFinishedNetworkReply, | ||
HttpStatusCode statusCode) { | ||
onNetworkError( | ||
pFinishedNetworkReply->error(), | ||
pFinishedNetworkReply->errorString(), | ||
WebResponseWithContent{ | ||
WebResponse{ | ||
pFinishedNetworkReply->url(), | ||
pFinishedNetworkReply->request().url(), | ||
statusCode}, | ||
readContentType(*pFinishedNetworkReply), | ||
readContentData(pFinishedNetworkReply).value_or(QByteArray{}), | ||
}); | ||
DEBUG_ASSERT(hasTerminated()); | ||
return; | ||
} | ||
|
||
} // namespace network | ||
|
||
} // namespace mixxx |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,11 @@ class WebTask : public NetworkTask { | |
const QString& errorString, | ||
const WebResponseWithContent& responseWithContent); | ||
|
||
protected: | ||
virtual void doNetworkError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The In contrast this seems to be an ordinary, overridable virtual function. It is also unclear even clear why and when you should override it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is you suggestion to improve this situation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O have renamed onNetworkError() to doNetworkError() |
||
QNetworkReply* pFinishedNetworkReply, | ||
HttpStatusCode statusCode); | ||
|
||
private: | ||
QUrl abortPendingNetworkReply(); | ||
|
||
|
@@ -199,7 +204,7 @@ class WebTask : public NetworkTask { | |
|
||
/// Handle network response. | ||
virtual void doNetworkReplyFinished( | ||
QNetworkReply* finishedNetworkReply, | ||
QNetworkReply* pFinishedNetworkReply, | ||
HttpStatusCode statusCode) = 0; | ||
|
||
/// Handle the abort and ensure that the task eventually | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could the internal state be already Failed when a network reply arrives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because this function is also called, before the request is issued and the state goes to the pending state.
mixxx/src/network/webtask.cpp
Line 200 in 41abb4d
Before, the state was artificially set to State::Pending, even though there was already a failure detected.
Probably just to trick the original assertion.
This is fixed now for a traceable usage of states.