Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core,okhttp: handle unresolved proxy addresses #3789

Merged
merged 1 commit into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ private static InetSocketAddress overrideProxy(String proxyHostPort) {
+ "be removed in a future release. Use the JVM flags "
+ "\"-Dhttps.proxyHost=HOST -Dhttps.proxyPort=PORT\" to set the https proxy for "
+ "this JVM.");
return new InetSocketAddress(parts[0], port);
// Return an unresolved InetSocketAddress to avoid DNS lookup
return InetSocketAddress.createUnresolved(parts[0], port);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,13 @@ sslSocketFactory, hostnameVerifier, sock, getOverridenHost(), getOverridenPort()
private Socket createHttpProxySocket(InetSocketAddress address, InetSocketAddress proxyAddress,
String proxyUsername, String proxyPassword) throws IOException, StatusException {
try {
Socket sock = new Socket(proxyAddress.getAddress(), proxyAddress.getPort());
Socket sock;
// The proxy address may not be resolved
if (proxyAddress.getAddress() != null) {
sock = new Socket(proxyAddress.getAddress(), proxyAddress.getPort());
} else {
sock = new Socket(proxyAddress.getHostName(), proxyAddress.getPort());
}
sock.setTcpNoDelay(true);

Source source = Okio.source(sock);
Expand Down
27 changes: 27 additions & 0 deletions okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,33 @@ public void proxy_immediateServerClose() throws Exception {
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
}

@Test
public void proxy_unresolvedProxyAddress() throws Exception {
clientTransport = new OkHttpClientTransport(
InetSocketAddress.createUnresolved("theservice", 80),
"authority",
"userAgent",
executor,
null,
null,
ConnectionSpec.CLEARTEXT,
DEFAULT_MAX_MESSAGE_SIZE,
InetSocketAddress.createUnresolved("unresolvedproxy", 80),
null,
null,
tooManyPingsRunnable);
clientTransport.start(transportListener);

ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(transportListener, timeout(TIME_OUT_MS)).transportShutdown(captor.capture());
Status error = captor.getValue();
assertTrue("Status didn't contain proxy: " + captor.getValue(),
error.getDescription().contains("proxy"));
assertEquals("Not UNAVAILABLE: " + captor.getValue(),
Status.UNAVAILABLE.getCode(), error.getCode());
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
}

@Test
public void goAway_notUtf8() throws Exception {
initTransport();
Expand Down