Author: chirino
Date: Fri Feb 23 12:23:08 2007
New Revision: 511081

URL: http://svn.apache.org/viewvc?view=rev&rev=511081
Log:
 [EMAIL PROTECTED]:  chirino | 2007-02-23 14:48:28 -0500
 Fixing memory leak that could occur if a connection attemp is not successful 
(for example if the broker is down and failover is not being used).
 If the client app loops re-attempting to reconnect and continues to fail, the 
leak to lead to a OOM exception quickly.
 
 

Modified:
    activemq/branches/activemq-4.1/   (props changed)
    
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
    
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java

Propchange: activemq/branches/activemq-4.1/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Fri Feb 23 12:23:08 2007
@@ -1 +1 @@
-635f1f41-eb29-0410-ac9d-be9e2c357fdd:/local/amq-4.1-port:236
+635f1f41-eb29-0410-ac9d-be9e2c357fdd:/local/amq-4.1-port:237

Modified: 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
URL: 
http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java?view=diff&rev=511081&r1=511080&r2=511081
==============================================================================
--- 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
 (original)
+++ 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
 Fri Feb 23 12:23:08 2007
@@ -573,10 +573,12 @@
                     }
 
                     if (isConnectionInfoSentToBroker) {
+                       // If we announced ourselfs to the broker.. Try to let 
the broker
+                       // know that the connection is being shutdown.
                         syncSendPacket(info.createRemoveCommand(), 
closeTimeout);
+                        asyncSendPacket(new ShutdownInfo());
                     }
 
-                    asyncSendPacket(new ShutdownInfo());
                     ServiceSupport.dispose(this.transport);
 
                     started.set(false);

Modified: 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java?view=diff&rev=511081&r1=511080&r2=511081
==============================================================================
--- 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
 (original)
+++ 
activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
 Fri Feb 23 12:23:08 2007
@@ -239,10 +239,10 @@
         if (brokerURL == null) {
             throw new ConfigurationException("brokerURL not set.");
         }
-        Transport transport;
+        ActiveMQConnection connection=null;
         try {
-            transport = createTransport();
-            ActiveMQConnection connection = 
createActiveMQConnection(transport, factoryStats);
+            Transport transport = createTransport();
+            connection = createActiveMQConnection(transport, factoryStats);
 
             connection.setUserName(userName);
             connection.setPassword(password);
@@ -268,9 +268,13 @@
             return connection;
         }
         catch (JMSException e) {
+               // Clean up!
+               try { connection.close(); } catch ( Throwable ignore ) {}
             throw e;
         }
         catch (Exception e) {
+               // Clean up!
+               try { connection.close(); } catch ( Throwable ignore ) {}
             throw JMSExceptionSupport.create("Could not connect to broker URL: 
" + brokerURL + ". Reason: " + e, e);
         }
     }


Reply via email to