https://issues.apache.org/jira/browse/AMQ-4889
Improve the stream close logic in the init method to ensure we don't leak and resources. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/720b8ace Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/720b8ace Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/720b8ace Branch: refs/heads/activemq-5.9 Commit: 720b8aceca0bf25b150e8f80c6f22e1c365f7fae Parents: f6ed548 Author: Timothy Bish <[email protected]> Authored: Wed Dec 4 11:09:28 2013 -0500 Committer: Hadrian Zbarcea <[email protected]> Committed: Wed Mar 12 13:13:20 2014 -0400 ---------------------------------------------------------------------- .../activemq/transport/nio/NIOSSLTransport.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/720b8ace/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java index 52c3e97..02789f3 100644 --- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java +++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java @@ -34,7 +34,6 @@ import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; -import org.apache.activemq.command.Command; import org.apache.activemq.command.ConnectionInfo; import org.apache.activemq.openwire.OpenWireFormat; import org.apache.activemq.thread.TaskRunnerFactory; @@ -75,6 +74,7 @@ public class NIOSSLTransport extends NIOTransport { @Override protected void initializeStreams() throws IOException { + NIOOutputStream outputStream = null; try { channel = socket.getChannel(); channel.configureBlocking(false); @@ -119,7 +119,7 @@ public class NIOSSLTransport extends NIOTransport { inputBuffer = ByteBuffer.allocate(sslSession.getPacketBufferSize()); inputBuffer.clear(); - NIOOutputStream outputStream = new NIOOutputStream(channel); + outputStream = new NIOOutputStream(channel); outputStream.setEngine(sslEngine); this.dataOut = new DataOutputStream(outputStream); this.buffOut = outputStream; @@ -127,6 +127,12 @@ public class NIOSSLTransport extends NIOTransport { handshakeStatus = sslEngine.getHandshakeStatus(); doHandshake(); } catch (Exception e) { + try { + if(outputStream != null) { + outputStream.close(); + } + super.closeStreams(); + } catch (Exception ex) {} throw new IOException(e); } } @@ -143,10 +149,12 @@ public class NIOSSLTransport extends NIOTransport { // listen for events telling us when the socket is readable. selection = SelectorManager.getInstance().register(channel, new SelectorManager.Listener() { + @Override public void onSelect(SelectorSelection selection) { serviceRead(); } + @Override public void onError(SelectorSelection selection, Throwable error) { if (error instanceof IOException) { onException((IOException) error); @@ -158,6 +166,7 @@ public class NIOSSLTransport extends NIOTransport { } } + @Override protected void serviceRead() { try { if (handshakeInProgress) { @@ -272,7 +281,7 @@ public class NIOSSLTransport extends NIOTransport { } else { currentBuffer.flip(); Object command = wireFormat.unmarshal(new DataInputStream(new NIOInputStream(currentBuffer))); - doConsume((Command) command); + doConsume(command); nextFrameSize = -1; currentBuffer = null; }
