Author: markt
Date: Tue Sep 23 13:25:01 2014
New Revision: 1627011
URL: http://svn.apache.org/r1627011
Log:
Protect against a user provided eviction policy throwing an exception and
stopping the Evictor thread.
Modified:
commons/proper/pool/trunk/src/changes/changes.xml
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1627011&r1=1627010&r2=1627011&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Tue Sep 23 13:25:01 2014
@@ -88,6 +88,10 @@ The <action> type attribute can be add,u
Prevent potential memory leaks with using an Evictor in a container
environment.
</action>
+ <action dev="markt" type="fix">
+ Protect against a user provided eviction policy throwing an exception and
+ stopping the Evictor thread.
+ </action>
</release>
<release version="2.2" date="2014-02-24" description=
"This is a maintenance release that adds a new testOnCreate configuration
option
Modified:
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1627011&r1=1627010&r2=1627011&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
Tue Sep 23 13:25:01 2014
@@ -935,8 +935,23 @@ public class GenericKeyedObjectPool<K,T>
continue;
}
- if (evictionPolicy.evict(evictionConfig, underTest,
- poolMap.get(evictionKey).getIdleObjects().size())) {
+ // User provided eviction policy could throw all sorts of
+ // crazy exceptions. Protect against such an exception
+ // killing the eviction thread.
+ boolean evict;
+ try {
+ evict = evictionPolicy.evict(evictionConfig, underTest,
+ poolMap.get(evictionKey).getIdleObjects().size());
+ } catch (Throwable t) {
+ // Slightly convoluted as SwallowedExceptionListener
+ // uses Exception rather than Throwable
+ PoolUtils.checkRethrow(t);
+ swallowException(new Exception(t));
+ // Don't evict on error conditions
+ evict = false;
+ }
+
+ if (evict) {
destroy(evictionKey, underTest, true);
destroyedByEvictorCount.incrementAndGet();
} else {
Modified:
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL:
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1627011&r1=1627010&r2=1627011&view=diff
==============================================================================
---
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
(original)
+++
commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java
Tue Sep 23 13:25:01 2014
@@ -780,8 +780,23 @@ public class GenericObjectPool<T> extend
continue;
}
- if (evictionPolicy.evict(evictionConfig, underTest,
- idleObjects.size())) {
+ // User provided eviction policy could throw all sorts of
+ // crazy exceptions. Protect against such an exception
+ // killing the eviction thread.
+ boolean evict;
+ try {
+ evict = evictionPolicy.evict(evictionConfig, underTest,
+ idleObjects.size());
+ } catch (Throwable t) {
+ // Slightly convoluted as SwallowedExceptionListener
+ // uses Exception rather than Throwable
+ PoolUtils.checkRethrow(t);
+ swallowException(new Exception(t));
+ // Don't evict on error conditions
+ evict = false;
+ }
+
+ if (evict) {
destroy(underTest);
destroyedByEvictorCount.incrementAndGet();
} else {