Skip to content

Commit 3bb8107

Browse files
committed
Add 1.5s timeout to ePDG DNS resolution
DNS resolution for non-existent ePDG domains (no SIM, non-standard carrier) could block VPN startup for 5-30 seconds. Wrap in a Future with 1.5s timeout — successful lookups typically complete in <500ms, so this catches most carriers while failing fast otherwise. https://claude.ai/code/session_01888KqFB93HxMCJGjscYT3X
1 parent 7d7859d commit 3bb8107

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) {
14741474
// TC excludes itself from the VPN (addDisallowedApplication), so this DNS resolution
14751475
// goes through the physical network — using the carrier's own DNS on cellular,
14761476
// which avoids geo-fencing issues. Re-resolved on each VPN rebuild (network switch).
1477+
// Uses a short timeout to avoid blocking VPN startup if resolution is slow.
14771478
// Requires Android 13+ (API 33) for excludeRoute().
14781479
if (Build.VERSION.SDK_INT >= 33)
14791480
try {
@@ -1482,16 +1483,24 @@ private Builder getBuilder(List<Rule> listAllowed, List<Rule> listRule) {
14821483
if (simOperator != null && simOperator.length() >= 5) {
14831484
String mcc = simOperator.substring(0, 3);
14841485
String mnc = simOperator.substring(3);
1485-
// Pad MNC to 3 digits per 3GPP TS 23.003
14861486
if (mnc.length() == 2)
14871487
mnc = "0" + mnc;
14881488
String epdgDomain = "epdg.epc.mnc" + mnc + ".mcc" + mcc + ".pub.3gppnetwork.org";
14891489
Log.i(TAG, "Resolving ePDG domain=" + epdgDomain);
1490-
for (InetAddress addr : InetAddress.getAllByName(epdgDomain)) {
1490+
1491+
// Resolve with 1.5s timeout to avoid blocking VPN startup
1492+
final String domain = epdgDomain;
1493+
java.util.concurrent.Future<InetAddress[]> future =
1494+
java.util.concurrent.Executors.newSingleThreadExecutor()
1495+
.submit(() -> InetAddress.getAllByName(domain));
1496+
InetAddress[] addrs = future.get(1500, java.util.concurrent.TimeUnit.MILLISECONDS);
1497+
for (InetAddress addr : addrs) {
14911498
Log.i(TAG, "Excluding ePDG address=" + addr.getHostAddress());
14921499
builder.excludeRoute(new IpPrefix(addr, addr instanceof Inet4Address ? 32 : 128));
14931500
}
14941501
}
1502+
} catch (java.util.concurrent.TimeoutException ex) {
1503+
Log.i(TAG, "ePDG resolution timed out, skipping");
14951504
} catch (Throwable ex) {
14961505
// Resolution may fail (no SIM, airplane mode, non-standard carrier) — not fatal
14971506
Log.i(TAG, "ePDG resolution skipped: " + ex.getMessage());

0 commit comments

Comments
 (0)