update_engine: call res_init and retry one extra time on unresolved host
libcurl error
Based on https://curl.haxx.se/docs/todo.html#updated_DNS_server_while_running:
"If /etc/resolv.conf gets updated while a program using libcurl is running, it
may cause name resolves to fail unless res_init() is called. We should
consider calling res_init() + retry once unconditionally on all name resolve
failures to mitigate against this."
This CL added following behavior:
On libcurl returns CURLE_COULDNT_RESOLVE_HOST error code:
1. we increase the max retry count by 1 for the first time it happens in the
lifetime of an LibcurlHttpFetcher object.
2. we call res_init unconditionally.
We also add UMA metrics to measure whether calling res_init helps
mitigate the unresolved host problem. WIP CL: https://chromium-review.googlesource.com/c/chromium/src/+/1698722
BUG=chromium:982813
TEST=FEATURES="test" emerge-kefka update_engine, tested on a device
Change-Id: Ia894eae93b3a0adbac1a831e657b75cba835dfa0
diff --git a/libcurl_http_fetcher.h b/libcurl_http_fetcher.h
index 3978b70..cdd489d 100644
--- a/libcurl_http_fetcher.h
+++ b/libcurl_http_fetcher.h
@@ -37,6 +37,48 @@
namespace chromeos_update_engine {
+// |UnresolvedHostStateMachine| is a representation of internal state machine of
+// |LibcurlHttpFetcher|.
+class UnresolvedHostStateMachine {
+ public:
+ UnresolvedHostStateMachine() = default;
+ enum class State {
+ kInit = 0,
+ kRetry = 1,
+ kRetriedSuccess = 2,
+ kNotRetry = 3,
+ };
+
+ State getState() { return state_; }
+
+ // Updates the following internal state machine:
+ //
+ // |kInit|
+ // |
+ // |
+ // \/
+ // (Try, host Unresolved)
+ // |
+ // |
+ // \/
+ // |kRetry| --> (Retry, host resolved)
+ // | |
+ // | |
+ // \/ \/
+ // (Retry, host Unresolved) |kRetriedSuccess|
+ // |
+ // |
+ // \/
+ // |kNotRetry|
+ //
+ void UpdateState(bool failed_to_resolve_host);
+
+ private:
+ State state_ = {State::kInit};
+
+ DISALLOW_COPY_AND_ASSIGN(UnresolvedHostStateMachine);
+};
+
class LibcurlHttpFetcher : public HttpFetcher {
public:
LibcurlHttpFetcher(ProxyResolver* proxy_resolver,
@@ -88,6 +130,8 @@
no_network_max_retries_ = retries;
}
+ int get_no_network_max_retries() { return no_network_max_retries_; }
+
void set_server_to_check(ServerToCheck server_to_check) {
server_to_check_ = server_to_check;
}
@@ -125,10 +169,8 @@
// Asks libcurl for the http response code and stores it in the object.
void GetHttpResponseCode();
- // Logs curl handle info.
- // This can be called only when an http request failed to avoid spamming the
- // logs. This must be called after |ResumeTransfer| and before |CleanUp|.
- void LogCurlHandleInfo();
+ // Returns the last |CURLcode|.
+ CURLcode GetCurlCode();
// Checks whether stored HTTP response is within the success range.
inline bool IsHttpResponseSuccess() {
@@ -280,6 +322,9 @@
// True if this object is for update check.
bool is_update_check_{false};
+ // Internal state machine.
+ UnresolvedHostStateMachine unresolved_host_state_machine_;
+
int low_speed_limit_bps_{kDownloadLowSpeedLimitBps};
int low_speed_time_seconds_{kDownloadLowSpeedTimeSeconds};
int connect_timeout_seconds_{kDownloadConnectTimeoutSeconds};