@@ -138,7 +138,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
138138 // First, do a basic connectivity check (against the parent zone)
139139 val basicCheck = withTimeoutOrNull(timeoutMs) {
140140 val randSub = generateRandomSubdomain()
141- performDnsQuery(host, port, " $randSub .$parentDomain " , DNS_TYPE_A )
141+ performDnsQuery(host, port, " $randSub .$parentDomain " , DNS_TYPE_A , timeoutMs )
142142 }
143143
144144 if (basicCheck == null ) {
@@ -205,7 +205,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
205205 val randSub = generateRandomSubdomain()
206206 val queryDomain = " $randSub .$testDomain "
207207 val result = withTimeoutOrNull(timeoutMs) {
208- performDnsQuery(host, port, queryDomain, recordType)
208+ performDnsQuery(host, port, queryDomain, recordType, timeoutMs )
209209 }
210210 // Success if we got a response OR if we got NXDOMAIN/NOERROR
211211 // (NXDOMAIN is acceptable - means server queried properly)
@@ -229,7 +229,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
229229 val randSub2 = generateRandomSubdomain()
230230 val queryDomain = " $randSub1 .$randSub2 .$testDomain "
231231 val result = withTimeoutOrNull(timeoutMs) {
232- performDnsQuery(host, port, queryDomain, DNS_TYPE_A )
232+ performDnsQuery(host, port, queryDomain, DNS_TYPE_A , timeoutMs )
233233 }
234234 // Any response (including NXDOMAIN) means the resolver processed the query
235235 result != null
@@ -330,7 +330,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
330330 for (ip in testNetIps) {
331331 try {
332332 val result = withTimeoutOrNull(timeoutMs) {
333- performDnsQuery(ip, 53 , testDomain, DNS_TYPE_A )
333+ performDnsQuery(ip, 53 , testDomain, DNS_TYPE_A , timeoutMs )
334334 }
335335 if (result != null ) {
336336 // A TEST-NET IP responded — ISP is intercepting DNS traffic
@@ -967,12 +967,13 @@ class ResolverScannerRepositoryImpl @Inject constructor(
967967 host : String ,
968968 port : Int ,
969969 domain : String ,
970- recordType : Int = DNS_TYPE_A
970+ recordType : Int = DNS_TYPE_A ,
971+ timeoutMs : Long = 3000
971972 ): DnsQueryResult = withContext(Dispatchers .IO ) {
972973 var socket: DatagramSocket ? = null
973974 try {
974975 socket = DatagramSocket ()
975- socket.soTimeout = 3000 // 3 second socket timeout
976+ socket.soTimeout = timeoutMs.toInt().coerceIn( 500 , 30000 )
976977
977978 val dnsQuery = buildDnsQuery(domain, recordType)
978979 val serverAddress = InetAddress .getByName(host)
@@ -1315,7 +1316,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
13151316 // the delegation "t.example.com NS ns.example.com").
13161317 val nsDomain = getParentDomain(testDomain)
13171318 val nsResult = withTimeoutOrNull(timeoutMs) {
1318- performDnsQuery(host, port, nsDomain, DNS_TYPE_NS )
1319+ performDnsQuery(host, port, nsDomain, DNS_TYPE_NS , timeoutMs )
13191320 } ? : return @withContext false
13201321
13211322 if (! nsResult.success || nsResult.rawResponse == null ) return @withContext false
@@ -1327,7 +1328,7 @@ class ResolverScannerRepositoryImpl @Inject constructor(
13271328 // Resolve the first NS hostname (glue record) via A query
13281329 val nsHostname = nsHosts[0 ].trimEnd(' .' )
13291330 val glueResult = withTimeoutOrNull(timeoutMs) {
1330- performDnsQuery(host, port, nsHostname, DNS_TYPE_A )
1331+ performDnsQuery(host, port, nsHostname, DNS_TYPE_A , timeoutMs )
13311332 } ? : return @withContext false
13321333
13331334 // Pass only if the A query succeeded and returned an IP
0 commit comments