Make DoT retries configurable
DnsTlsTransport re-issues pending queries when onClosed is called.
The call to onClosed is triggered when 1) asynchronous handshake
fails and 2) SSL socket idles for 20 seconds. In either case, retry
on the same DoT server is not always a good solution. Instead, there
are some considerable options, like trying next DoT server, fallbacking
to Do53, or simply returning query failure.
Tuning DoT retries is especially significant to asynchronous
handshake feature because the timeout of the feature is calculated as:
timeout = dot_connect_timeout_ms * dot_maxtries
Bug: 149445907
Test: cd packages/modules/DnsResolver
atest with combination of (dot_async_handshake, dot_maxtries)
which are (0, 3), (0, 1), (1, 3), and (1, 1)
Change-Id: Iceb7bc7f0f6736d900384d1a11eea470761ee32c
diff --git a/resolv_tls_unit_test.cpp b/resolv_tls_unit_test.cpp
index 261b2e6..78f98cb 100644
--- a/resolv_tls_unit_test.cpp
+++ b/resolv_tls_unit_test.cpp
@@ -32,6 +32,7 @@
#include "DnsTlsSessionCache.h"
#include "DnsTlsSocket.h"
#include "DnsTlsTransport.h"
+#include "Experiments.h"
#include "IDnsTlsSocket.h"
#include "IDnsTlsSocketFactory.h"
#include "IDnsTlsSocketObserver.h"
@@ -43,6 +44,8 @@
using netdutils::makeSlice;
using netdutils::Slice;
+static const std::string DOT_MAXTRIES_FLAG = "dot_maxtries";
+
typedef std::vector<uint8_t> bytevec;
static void parseServer(const char* server, in_port_t port, sockaddr_storage* parsed) {
@@ -476,8 +479,9 @@
EXPECT_EQ(DnsTlsTransport::Response::network_error, r.code);
EXPECT_TRUE(r.response.empty());
- // Reconnections are triggered since DnsTlsQueryMap is not empty.
- EXPECT_EQ(transport.getConnectCounter(), DnsTlsQueryMap::kMaxTries);
+ // Reconnections might be triggered depending on the flag.
+ EXPECT_EQ(transport.getConnectCounter(),
+ Experiments::getInstance()->getFlag(DOT_MAXTRIES_FLAG, DnsTlsQueryMap::kMaxTries));
}
// Simulate a server that occasionally closes the connection and silently
@@ -572,8 +576,9 @@
EXPECT_TRUE(r.response.empty());
}
- // Reconnections are triggered since DnsTlsQueryMap is not empty.
- EXPECT_EQ(transport.getConnectCounter(), DnsTlsQueryMap::kMaxTries);
+ // Reconnections might be triggered depending on the flag.
+ EXPECT_EQ(transport.getConnectCounter(),
+ Experiments::getInstance()->getFlag(DOT_MAXTRIES_FLAG, DnsTlsQueryMap::kMaxTries));
}
TEST_F(TransportTest, PartialDrop) {