Author: chirino
Date: Mon Nov 5 10:47:16 2007
New Revision: 592114
URL: http://svn.apache.org/viewvc?rev=592114&view=rev
Log:
- memory leak fix: TransportConnection would leak memory if an error occured
while start()ing the connection. Most visible when you create a network
connector pointing at a remote broker that was down since this loops through
creating TransportConnectors every few seconds.
- Deadlock fix VMTransport could dead lock if during start() an error occured
and stop was recusively called.
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java?rev=592114&r1=592113&r2=592114&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/TransportConnection.java
Mon Nov 5 10:47:16 2007
@@ -846,6 +846,10 @@
active = true;
this.processDispatch(connector.getBrokerInfo());
connector.onStarted(this);
+ } catch (Exception e) {
+ // Force clean up on an error starting up.
+ stop();
+ throw e;
} finally {
// stop() can be called from within the above block,
// but we want to be sure start() completes before
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java?rev=592114&r1=592113&r2=592114&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/thread/Valve.java
Mon Nov 5 10:47:16 2007
@@ -48,7 +48,7 @@
}
}
- boolean isOn() {
+ public boolean isOn() {
synchronized (mutex) {
return on;
}
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java?rev=592114&r1=592113&r2=592114&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java
Mon Nov 5 10:47:16 2007
@@ -115,7 +115,7 @@
enqueueValve.turnOff();
if (messageQueue != null && !async) {
Object command;
- while ((command = messageQueue.poll()) != null) {
+ while ((command = messageQueue.poll()) != null &&
!stopping.get() ) {
transportListener.onCommand(command);
}
}
@@ -124,27 +124,37 @@
} finally {
enqueueValve.turnOn();
}
+ // If we get stopped while starting up, then do the actual stop now
+ // that the enqueueValve is back on.
+ if( stopping.get() ) {
+ stop();
+ }
}
public void stop() throws Exception {
- TaskRunner tr = null;
- try {
- stopping.set(true);
- enqueueValve.turnOff();
- if (!disposed) {
- started = false;
- disposed = true;
- if (taskRunner != null) {
- tr = taskRunner;
- taskRunner = null;
+ stopping.set(true);
+
+ // If stop() is called while being start()ed.. then we can't stop
until we return to the start() method.
+ if( enqueueValve.isOn() ) {
+
+ TaskRunner tr = null;
+ try {
+ enqueueValve.turnOff();
+ if (!disposed) {
+ started = false;
+ disposed = true;
+ if (taskRunner != null) {
+ tr = taskRunner;
+ taskRunner = null;
+ }
}
+ } finally {
+ stopping.set(false);
+ enqueueValve.turnOn();
+ }
+ if (tr != null) {
+ tr.shutdown(1000);
}
- } finally {
- stopping.set(false);
- enqueueValve.turnOn();
- }
- if (tr != null) {
- tr.shutdown(1000);
}
}