Skip to content

Commit a908b5e

Browse files
committed
android: For UDS, use fake IP instead of localhost
This avoids a DNS lookup, which can be slow and fail. Fixes #11442
1 parent d169a5d commit a908b5e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

android/src/main/java/io/grpc/android/UdsChannelBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ public static ManagedChannelBuilder<?> forPath(String path, Namespace namespace)
6868
throw new UnsupportedOperationException("OkHttpChannelBuilder not found on the classpath");
6969
}
7070
try {
71-
// Target 'dns:///localhost' is unused, but necessary as an argument for OkHttpChannelBuilder.
71+
// Target 'dns:///127.0.0.1' is unused, but necessary as an argument for OkHttpChannelBuilder.
72+
// An IP address is used instead of localhost to avoid a DNS lookup (see #11442). This should
73+
// work even if IPv4 is unavailable, as the DNS resolver doesn't need working IPv4 to parse an
74+
// IPv4 address. Unavailable IPv4 fails when we connect(), not at resolution time.
7275
// TLS is unsupported because Conscrypt assumes the platform Socket implementation to improve
7376
// performance by using the file descriptor directly.
7477
Object o = OKHTTP_CHANNEL_BUILDER_CLASS
7578
.getMethod("forTarget", String.class, ChannelCredentials.class)
76-
.invoke(null, "dns:///localhost", InsecureChannelCredentials.create());
79+
.invoke(null, "dns:///127.0.0.1", InsecureChannelCredentials.create());
7780
ManagedChannelBuilder<?> builder = OKHTTP_CHANNEL_BUILDER_CLASS.cast(o);
7881
OKHTTP_CHANNEL_BUILDER_CLASS
7982
.getMethod("socketFactory", SocketFactory.class)

0 commit comments

Comments
 (0)