From 840ca30e90d02dadda311f2c9ce44a8045bd6801 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 9 Jul 2013 19:40:08 +0000 Subject: [PATCH] workaround for issue: https://issues.apache.org/jira/browse/AMQ-4307 attempt to get around the deadlock by detecting and interrupting the locked thread. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1501488 13f79535-47bb-0310-9956-ffa450edef68 --- .../transport/http/HttpClientTransport.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java index 077ee24236..c5bcc5ce61 100755 --- a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java +++ b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java @@ -92,6 +92,7 @@ public class HttpClientTransport extends HttpTransportSupport { return null; } + @Override public void oneway(Object command) throws IOException { if (isStopped()) { @@ -142,6 +143,7 @@ public class HttpClientTransport extends HttpTransportSupport { } } + @Override public Object request(Object command) throws IOException { return null; } @@ -155,6 +157,7 @@ public class HttpClientTransport extends HttpTransportSupport { } } + @Override public void run() { if (LOG.isTraceEnabled()) { @@ -188,7 +191,7 @@ public class HttpClientTransport extends HttpTransportSupport { } else { receiveCounter++; DataInputStream stream = createDataInputStream(answer); - Object command = (Object)getTextWireFormat().unmarshal(stream); + Object command = getTextWireFormat().unmarshal(stream); if (command == null) { LOG.debug("Received null command from url: " + remoteUrl); } else { @@ -236,6 +239,7 @@ public class HttpClientTransport extends HttpTransportSupport { // Implementation methods // ------------------------------------------------------------------------- + @Override protected void doStart() throws Exception { if (LOG.isTraceEnabled()) { @@ -268,7 +272,6 @@ public class HttpClientTransport extends HttpTransportSupport { } }; - try { httpClient.execute(httpMethod, new BasicResponseHandler()); httpClient.execute(optionsMethod, handler); @@ -279,9 +282,31 @@ public class HttpClientTransport extends HttpTransportSupport { super.doStart(); } + @Override protected void doStop(ServiceStopper stopper) throws Exception { if (httpMethod != null) { - httpMethod.abort(); + // In some versions of the JVM a race between the httpMethod and the completion + // of the method when using HTTPS can lead to a deadlock. This hack attempts to + // detect that and interrupt the thread that's locked so that they can complete + // on another attempt. + for (int i = 0; i < 3; ++i) { + Thread abortThread = new Thread(new Runnable() { + + @Override + public void run() { + try { + httpMethod.abort(); + } catch (Exception e) { + } + } + }); + + abortThread.start(); + abortThread.join(2000); + if (!abortThread.isAlive()) { + abortThread.interrupt(); + } + } } } @@ -325,6 +350,7 @@ public class HttpClientTransport extends HttpTransportSupport { this.trace = trace; } + @Override public int getReceiveCounter() { return receiveCounter; }