summaryrefslogtreecommitdiff
path: root/methods/basehttp.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-10-26 00:57:26 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2017-12-13 23:56:29 +0100
commit47c0bdc310c8cd62374ca6e6bb456dd183bdfc07 (patch)
treeb951a0221dd6015ffef42ebea9dfc709f6053404 /methods/basehttp.cc
parent2f6aed72f656494d668918aa8ce4052d7c81e993 (diff)
report transient errors as transient errors
The Fail method for acquire methods has a boolean parameter indicating the transient-nature of a reported error. The problem with this is that Fail is called very late at a point where it is no longer easily identifiable if an error is indeed transient or not, so some calls were and some weren't and the acquire system would later mostly ignore the transient flag and guess by using the FailReason instead. Introducing a tri-state enum we can pass the information about fatal or transient errors through the callstack to generate the correct fails.
Diffstat (limited to 'methods/basehttp.cc')
-rw-r--r--methods/basehttp.cc45
1 files changed, 30 insertions, 15 deletions
diff --git a/methods/basehttp.cc b/methods/basehttp.cc
index 3b4c60720..2473ecb5c 100644
--- a/methods/basehttp.cc
+++ b/methods/basehttp.cc
@@ -74,9 +74,8 @@ ServerState::RunHeadersResult ServerState::RunHeaders(RequestState &Req,
Persistent = false;
return RUN_HEADERS_OK;
- }
- while (LoadNextResponse(false, Req) == true);
-
+ } while (LoadNextResponse(false, Req) == ResultState::SUCCESSFUL);
+
return RUN_HEADERS_IO_ERROR;
}
/*}}}*/
@@ -598,11 +597,18 @@ int BaseHttpMethod::Loop()
QueueBack = Queue;
// Connect to the host
- if (Server->Open() == false)
+ switch (Server->Open())
{
+ case ResultState::FATAL_ERROR:
+ Fail(false);
+ Server = nullptr;
+ continue;
+ case ResultState::TRANSIENT_ERROR:
Fail(true);
Server = nullptr;
continue;
+ case ResultState::SUCCESSFUL:
+ break;
}
// Fill the pipeline.
@@ -657,13 +663,13 @@ int BaseHttpMethod::Loop()
URIStart(Res);
// Run the data
- bool Result = true;
+ ResultState Result = ResultState::SUCCESSFUL;
- // ensure we don't fetch too much
- // we could do "Server->MaximumSize = Queue->MaximumSize" here
- // but that would break the clever pipeline messup detection
- // so instead we use the size of the biggest item in the queue
- Req.MaximumSize = FindMaximumObjectSizeInQueue();
+ // ensure we don't fetch too much
+ // we could do "Server->MaximumSize = Queue->MaximumSize" here
+ // but that would break the clever pipeline messup detection
+ // so instead we use the size of the biggest item in the queue
+ Req.MaximumSize = FindMaximumObjectSizeInQueue();
if (Req.HaveContent)
{
@@ -692,10 +698,10 @@ int BaseHttpMethod::Loop()
SetFailReason("MaximumSizeExceeded");
_error->Error(_("File has unexpected size (%llu != %llu). Mirror sync in progress?"),
filesize, Queue->ExpectedHashes.FileSize());
- Result = false;
+ Result = ResultState::FATAL_ERROR;
}
}
- if (Result)
+ if (Result == ResultState::SUCCESSFUL)
Result = Server->RunData(Req);
}
@@ -715,7 +721,7 @@ int BaseHttpMethod::Loop()
utimes(Queue->DestFile.c_str(), times);
// Send status to APT
- if (Result == true)
+ if (Result == ResultState::SUCCESSFUL)
{
Hashes * const resultHashes = Server->GetHashes();
HashStringList const hashList = resultHashes->GetHashStringList();
@@ -768,8 +774,17 @@ int BaseHttpMethod::Loop()
else
{
Server->Close();
- Fail(true);
- }
+ switch (Result)
+ {
+ case ResultState::TRANSIENT_ERROR:
+ Fail(true);
+ break;
+ case ResultState::FATAL_ERROR:
+ case ResultState::SUCCESSFUL:
+ Fail(false);
+ break;
+ }
+ }
}
break;
}