You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2016/03/09 21:17:49 UTC
knox git commit: [KNOX-685] - Knox tests cleanup after Jetty 9
upgrade. Test slow dns resolution timeout fix.
Repository: knox
Updated Branches:
refs/heads/master 8013ff479 -> 3becd55dd
[KNOX-685] - Knox tests cleanup after Jetty 9 upgrade. Test slow dns resolution timeout fix.
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/3becd55d
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/3becd55d
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/3becd55d
Branch: refs/heads/master
Commit: 3becd55ddd7d6e2591c2968444341c98c1fa61e2
Parents: 8013ff4
Author: Kevin Minder <km...@apache.org>
Authored: Wed Mar 9 15:16:03 2016 -0500
Committer: Kevin Minder <km...@apache.org>
Committed: Wed Mar 9 15:16:03 2016 -0500
----------------------------------------------------------------------
.../filter/rewrite/impl/UrlRewriteResponse.java | 46 +++++++++++++++++---
1 file changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/3becd55d/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index d07cc17..59676a3 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -52,6 +52,13 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipException;
@@ -68,6 +75,8 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
private static final UrlRewriteMessages LOG = MessagesFactory.get( UrlRewriteMessages.class );
+ private static final ExecutorService DNS_LOOKUP_THREAD_POOL = Executors.newCachedThreadPool();
+
// An 8K buffer better matches the underlying buffer sizes.
// Testing with 16K made no appreciable difference.
private static final int STREAM_BUFFER_SIZE = 8 * 1024;
@@ -218,19 +227,44 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
}
}
+ private static class AsyncDnsRequest implements Callable<String> {
+ private String hostName;
+ public AsyncDnsRequest( String hostName ) {
+ this.hostName = hostName;
+ }
+ @Override
+ public String call() throws Exception {
+ String resolvedHostName = hostName;
+ try {
+ LOGGER.debug( "LOOKUP HOSTNAME FOR " + hostName );
+ resolvedHostName = InetAddress.getByName( hostName ).getHostName();
+ LOGGER.debug( "FOUND HOSTNAME " + resolvedHostName );
+ } catch( UnknownHostException e ) {
+ // Ignore it and use the original hostname.
+ LOGGER.debug( "FAILED TO RESOLVE " + hostName );
+ e.printStackTrace();
+ }
+ return resolvedHostName;
+ }
+ }
+
// KNOX-464: Doing this because Jetty only returns the string version of the IP address for request.getLocalName().
// Hopefully the local hostname will be cached so this will not be a significant performance hit.
// Previously this was an inline request.getServerName() but this ended up mixing the hostname from the Host header
// and the local port which was making load balancer configuration difficult if not impossible.
private String getRequestLocalHostName() {
String hostName = request.getLocalName();
+ Future<String> future = DNS_LOOKUP_THREAD_POOL.submit( new AsyncDnsRequest( hostName ) );
try {
- LOGGER.debug( "LOOKUP HOSTNAME FOR " + hostName );
- hostName = InetAddress.getByName( hostName ).getHostName();
- LOGGER.debug( "FOUND HOSTNAME " + hostName );
- } catch( UnknownHostException e ) {
- // Ignore it and use the original hostname.
- LOGGER.debug( "FAILED TO RESOLVE " + hostName );
+ hostName = future.get( 100, TimeUnit.MILLISECONDS );
+ } catch( TimeoutException e ) {
+ LOGGER.debug( "TIMEOUT RESOLVING " + hostName );
+ e.printStackTrace();
+ } catch( InterruptedException e ) {
+ LOGGER.debug( "INTERRUPTED RESOLVING " + hostName );
+ e.printStackTrace();
+ } catch( ExecutionException e ) {
+ LOGGER.debug( "ERROR RESOLVING " + hostName );
e.printStackTrace();
}
return hostName;