Enlarge the DoH query timeout and the server probe timeout
query timeout: from 2s to 30s
probe timeout: from 3s to 60s
Bug: 194048056
Test: atest
Change-Id: Ib11b17da7093b1d438ee8c7399694c2b19abeae9
diff --git a/Experiments.h b/Experiments.h
index dbe21fc..35c28ce 100644
--- a/Experiments.h
+++ b/Experiments.h
@@ -62,6 +62,8 @@
"dot_validation_latency_factor",
"dot_validation_latency_offset_ms",
"doh",
+ "doh_query_timeout_ms",
+ "doh_probe_timeout_ms",
"mdns_resolution",
};
// This value is used in updateInternal as the default value if any flags can't be found.
diff --git a/PrivateDnsConfiguration.cpp b/PrivateDnsConfiguration.cpp
index 8960460..75dd24f 100644
--- a/PrivateDnsConfiguration.cpp
+++ b/PrivateDnsConfiguration.cpp
@@ -462,8 +462,13 @@
mPrivateDnsLog.push(std::move(record));
LOG(INFO) << __func__ << ": Upgrading server to DoH: " << name;
+ int probeTimeout = Experiments::getInstance()->getFlag("doh_probe_timeout_ms",
+ kDohProbeDefaultTimeoutMs);
+ if (probeTimeout < 1000) {
+ probeTimeout = 1000;
+ }
return doh_net_new(mDohDispatcher, netId, dohId.httpsTemplate.c_str(), dohId.host.c_str(),
- dohId.ipAddr.c_str(), mark, caCert.c_str(), 3000);
+ dohId.ipAddr.c_str(), mark, caCert.c_str(), probeTimeout);
}
LOG(INFO) << __func__ << ": No suitable DoH server found";
diff --git a/PrivateDnsConfiguration.h b/PrivateDnsConfiguration.h
index 6c2a76b..6b15be2 100644
--- a/PrivateDnsConfiguration.h
+++ b/PrivateDnsConfiguration.h
@@ -60,6 +60,9 @@
class PrivateDnsConfiguration {
public:
+ static constexpr int kDohQueryDefaultTimeoutMs = 30000;
+ static constexpr int kDohProbeDefaultTimeoutMs = 60000;
+
struct ServerIdentity {
const netdutils::IPSockAddr sockaddr;
const std::string provider;
diff --git a/res_send.cpp b/res_send.cpp
index 6ddb63f..9bd912c 100644
--- a/res_send.cpp
+++ b/res_send.cpp
@@ -128,6 +128,7 @@
using android::net::DnsTlsDispatcher;
using android::net::DnsTlsServer;
using android::net::DnsTlsTransport;
+using android::net::Experiments;
using android::net::IpVersion;
using android::net::IV_IPV4;
using android::net::IV_IPV6;
@@ -1393,7 +1394,12 @@
const unsigned netId = statp->netid;
LOG(INFO) << __func__ << ": performing query over Https";
Stopwatch queryStopwatch;
- ssize_t result = privateDnsConfiguration.dohQuery(netId, query, answer, /*timeoutMs*/ 2000);
+ int queryTimeout = Experiments::getInstance()->getFlag(
+ "doh_query_timeout_ms", PrivateDnsConfiguration::kDohQueryDefaultTimeoutMs);
+ if (queryTimeout < 1000) {
+ queryTimeout = 1000;
+ }
+ ssize_t result = privateDnsConfiguration.dohQuery(netId, query, answer, queryTimeout);
LOG(INFO) << __func__ << ": Https query result: " << result;
if (result == RESULT_CAN_NOT_SEND) return RESULT_CAN_NOT_SEND;
diff --git a/tests/resolv_private_dns_test.cpp b/tests/resolv_private_dns_test.cpp
index 68d6685..d1d7160 100644
--- a/tests/resolv_private_dns_test.cpp
+++ b/tests/resolv_private_dns_test.cpp
@@ -40,6 +40,8 @@
using std::chrono::milliseconds;
const std::string kDohFlag("persist.device_config.netd_native.doh");
+const std::string kDohQueryTimeoutFlag("persist.device_config.netd_native.doh_query_timeout_ms");
+const std::string kDohProbeTimeoutFlag("persist.device_config.netd_native.doh_probe_timeout_ms");
namespace {
@@ -153,6 +155,11 @@
protected:
void SetUp() override {
mDohScopedProp = make_unique<ScopedSystemProperties>(kDohFlag, "1");
+ mDohQueryTimeoutScopedProp =
+ make_unique<ScopedSystemProperties>(kDohQueryTimeoutFlag, "1000");
+ unsigned int expectedProbeTimeout = kExpectedDohValidationTimeWhenTimeout.count();
+ mDohProbeTimeoutScopedProp = make_unique<ScopedSystemProperties>(
+ kDohProbeTimeoutFlag, std::to_string(expectedProbeTimeout));
BaseTest::SetUp();
static const std::vector<DnsRecord> records = {
@@ -195,7 +202,7 @@
std::this_thread::sleep_for(kExpectedDohValidationTimeWhenServerUnreachable);
}
- static constexpr milliseconds kExpectedDohValidationTimeWhenTimeout{3000};
+ static constexpr milliseconds kExpectedDohValidationTimeWhenTimeout{1000};
static constexpr milliseconds kExpectedDohValidationTimeWhenServerUnreachable{1000};
static constexpr char kQueryHostname[] = "TransportParameterizedTest.example.com.";
static constexpr char kQueryAnswerA[] = "1.2.3.4";
@@ -207,8 +214,10 @@
test::DNSResponder doh_backend{"127.0.1.3", "53"};
test::DNSResponder dot_backend{"127.0.2.3", "53"};
- // Used to enable DoH during the tests.
+ // Used to enable DoH during the tests and set up a shorter timeout.
std::unique_ptr<ScopedSystemProperties> mDohScopedProp;
+ std::unique_ptr<ScopedSystemProperties> mDohQueryTimeoutScopedProp;
+ std::unique_ptr<ScopedSystemProperties> mDohProbeTimeoutScopedProp;
};
// Parameterized test for the combination of DoH and DoT.