commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 18062] New: - borrowObject/validation infinite loop and deadlock issue in GenericObjectPool
Date Mon, 17 Mar 2003 12:51:46 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18062>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18062

borrowObject/validation infinite loop and deadlock issue in GenericObjectPool

           Summary: borrowObject/validation infinite loop and deadlock issue
                    in GenericObjectPool
           Product: Commons
           Version: 1.0.1 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: Other
         Component: Pool
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: sebster@sebster.com


An infinite loop and deadlocks occurs when:

1) no valid elements are in the pool
2) validation is turned on
3) makeObject fails te create a valid object (infinite loop)
4) other threads call borrowObject (deadlocks)

An example of the above condition occurs when using DBCP and allowing validation
by query. If the query is invalid, the connection is made but the query
immediately fails (causing validateObject to return false). This causes
borrowObject to loop infinitely, making and destroying connections continuously,
 keeping the synchronized lock it obtained. This causes all other threads which
call borrowObject to deadlock.

Below is a fix:

--- GenericObjectPool.java.orig 2003-03-17 13:09:33.000000000 +0100
+++ GenericObjectPool.java      2003-03-17 13:33:44.000000000 +0100
@@ -712,11 +712,13 @@
 
     public synchronized Object borrowObject() throws Exception {
         long starttime = System.currentTimeMillis();
+        boolean isNew = true;
         for(;;) {
             ObjectTimestampPair pair = null;
             // if there are any sleeping, just grab one of those
             try {
                 pair = (ObjectTimestampPair)(_pool.removeFirst());
+                isNew = false;
             } catch(NoSuchElementException e) { /* ignored */
             }
             // otherwise
@@ -763,6 +765,9 @@
                     ; // ignored, we're throwing it out anyway
                 }
                 _factory.destroyObject(pair.value);
+                if (isNew) {
+                    throw new NoSuchElementException("Could not create a
validated object");
+                }
             } else {
                 _numActive++;
                 return pair.value;

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message