Bring aisapi handling closer to LL (code 499 retry, match timeout values, etc)

This commit is contained in:
Shyotl
2020-04-02 20:07:42 -05:00
parent cc034f6841
commit 445eb29bd3
3 changed files with 31 additions and 21 deletions

View File

@@ -961,3 +961,4 @@ P(wholeModelFeeResponder);
P(wholeModelUploadResponder); P(wholeModelUploadResponder);
P2(XMLRPCResponder, connect_40s); P2(XMLRPCResponder, connect_40s);
P(getUpdateInfoResponder); P(getUpdateInfoResponder);
P2(AISAPIResponder, connect_60s);

View File

@@ -40,6 +40,8 @@
/// Classes for AISv3 support. /// Classes for AISv3 support.
///---------------------------------------------------------------------------- ///----------------------------------------------------------------------------
extern AIHTTPTimeoutPolicy AISAPIResponder_timeout;
class AISCommand final : public LLHTTPClient::ResponderWithCompleted class AISCommand final : public LLHTTPClient::ResponderWithCompleted
{ {
public: public:
@@ -54,8 +56,11 @@ public:
mType(type) mType(type)
{} {}
virtual AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy(void) const { return AISAPIResponder_timeout; }
void run( command_func_type func ) void run( command_func_type func )
{ {
LL_WARNS("Inventory") << "Sending request for " << getName() <<": " << mURL << LL_ENDL;
(mCommandFunc = func)(); (mCommandFunc = func)();
} }
@@ -64,6 +69,7 @@ public:
return mName; return mName;
} }
private:
void markComplete() void markComplete()
{ {
// Command func holds a reference to self, need to release it // Command func holds a reference to self, need to release it
@@ -72,34 +78,39 @@ public:
mRetryPolicy->onSuccess(); mRetryPolicy->onSuccess();
} }
void malformedResponse() { mStatus = HTTP_INTERNAL_ERROR_OTHER; mReason = llformat("Malformed response contents (original code: %d)", mStatus); }
bool onFailure() bool onFailure()
{ {
bool retry = mStatus != HTTP_INTERNAL_ERROR_OTHER && mStatus != 410; // We handle these and stop mRetryPolicy->onFailure(mStatus, getResponseHeaders());
LL_WARNS("Inventory") << "Inventory error: " << dumpResponse() << LL_ENDL;
if (retry) mRetryPolicy->onFailure(mStatus, getResponseHeaders());
F32 seconds_to_wait; F32 seconds_to_wait;
if (retry && mRetryPolicy->shouldRetry(seconds_to_wait)) if (mRetryPolicy->shouldRetry(seconds_to_wait))
{ {
LL_WARNS("Inventory") << "Retrying in " << seconds_to_wait << "seconds due to inventory error for " << getName() <<": " << dumpResponse() << LL_ENDL;
doAfterInterval(mCommandFunc,seconds_to_wait); doAfterInterval(mCommandFunc,seconds_to_wait);
return true;
} }
else else
{ {
// Command func holds a reference to self, need to release it // Command func holds a reference to self, need to release it
// after a success or final failure. // after a success or final failure.
// *TODO: Notify user? This seems bad. // *TODO: Notify user? This seems bad.
LL_WARNS("Inventory") << "Abort due to inventory error for " << getName() <<": " << dumpResponse() << LL_ENDL;
mCommandFunc = no_op; mCommandFunc = no_op;
return false;
} }
return retry;
} }
protected: protected:
void httpCompleted() override void httpCompleted() override
{ {
AISAPI::InvokeAISCommandCoro(this, getURL(), mTargetId, getContent(), mCompletionFunc, (AISAPI::COMMAND_TYPE)mType); // Continue through if successful or longer retrying,
if (isGoodStatus(mStatus) || !onFailure())
{
markComplete();
AISAPI::InvokeAISCommandCoro(this, getURL(), mTargetId, getContent(), mCompletionFunc, (AISAPI::COMMAND_TYPE)mType);
}
} }
private:
command_func_type mCommandFunc; command_func_type mCommandFunc;
LLPointer<LLHTTPRetryPolicy> mRetryPolicy; LLPointer<LLHTTPRetryPolicy> mRetryPolicy;
AISAPI::completion_t mCompletionFunc; AISAPI::completion_t mCompletionFunc;
@@ -312,20 +323,20 @@ void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t
boost::intrusive_ptr< AISCommand > responder = new AISCommand(UPDATEITEM, "UpdateItem",itemId, callback); boost::intrusive_ptr< AISCommand > responder = new AISCommand(UPDATEITEM, "UpdateItem",itemId, callback);
responder->run(boost::bind(&LLHTTPClient::patch, url, updates, responder/*,*/ DEBUG_CURLIO_PARAM(debug_off), keep_alive, (AIStateMachine*)NULL, 0)); responder->run(boost::bind(&LLHTTPClient::patch, url, updates, responder/*,*/ DEBUG_CURLIO_PARAM(debug_off), keep_alive, (AIStateMachine*)NULL, 0));
} }
void AISAPI::InvokeAISCommandCoro(AISCommand* responder, void AISAPI::InvokeAISCommandCoro(LLHTTPClient::ResponderWithCompleted* responder,
std::string url, std::string url,
LLUUID targetId, LLSD result, completion_t callback, COMMAND_TYPE type) LLUUID targetId, LLSD result, completion_t callback, COMMAND_TYPE type)
{ {
LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL;
auto status = responder->getStatus(); auto status = responder->getStatus();
if (!responder->isGoodStatus(status) || !result.isMap()) if (!responder->isGoodStatus(status) || !result.isMap())
{ {
if (!result.isMap()) if (!result.isMap())
{ {
responder->malformedResponse(); LL_WARNS("Inventory") << "Inventory error: " << HTTP_INTERNAL_ERROR_OTHER << ": " << "Malformed response contents" << LL_ENDL;
} }
else if (status == 410) //GONE else if (status == 410) //GONE
{ {
// Item does not exist or was already deleted from server. // Item does not exist or was already deleted from server.
@@ -359,12 +370,10 @@ void AISAPI::InvokeAISCommandCoro(AISCommand* responder,
gInventory.onObjectDeletedFromServer(targetId); gInventory.onObjectDeletedFromServer(targetId);
} }
} }
LL_WARNS("Inventory") << "Inventory error: " << status << ": " << responder->getReason() << LL_ENDL;
} }
// Keep these statuses accounted for in the responder too LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL;
if (responder->onFailure()) // If we're retrying, exit early.
return;
} }
else responder->markComplete();
gInventory.onAISUpdateReceived("AISCommand", result); gInventory.onAISUpdateReceived("AISCommand", result);

View File

@@ -72,7 +72,7 @@ private:
static std::string getInvCap(); static std::string getInvCap();
static std::string getLibCap(); static std::string getLibCap();
static void InvokeAISCommandCoro(class AISCommand* responder, static void InvokeAISCommandCoro(LLHTTPClient::ResponderWithCompleted* responder,
std::string url, LLUUID targetId, LLSD body, std::string url, LLUUID targetId, LLSD body,
completion_t callback, COMMAND_TYPE type); completion_t callback, COMMAND_TYPE type);
}; };