You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Phil Steitz (JIRA)" <ji...@apache.org> on 2008/01/06 23:58:34 UTC

[jira] Commented: (POOL-120) maxActive can be exceeded by one

    [ https://issues.apache.org/jira/browse/POOL-120?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556446#action_12556446 ] 

Phil Steitz commented on POOL-120:
----------------------------------

The problem occurs because addObject does not update pool statistics before kicking off the makeObject, so a thread executing borrowObject sees neither an available idle object nor an increment to _numActive.  
The simplest fix for this is 
a) synchronize (fully) addObject, as in 1.3. 
Alternatives are
b) introduce a flag indicating that addObject has a makeObject in progress and make borrowObject check that flag before initiating makeObject 
c) introduce a _numTotal field that accurately tracks all objects in circulation, follow the pattern increment before makeObject, decrement after destroyObject and enforce the invariant _numTotal < _maxActive.

My inclination is a), since it minimizes code change and affects only addObject / ensureMinIdle.  



> maxActive can be exceeded by one
> --------------------------------
>
>                 Key: POOL-120
>                 URL: https://issues.apache.org/jira/browse/POOL-120
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 1.2
>            Reporter: Phil Steitz
>            Priority: Blocker
>             Fix For: 1.4
>
>
> For GenericObjectPool, when numIdle > 0 and the idle object evictor is set to run (timeBetweenEvictionRunsMillis > 0), a race condition can occur between the Evictor and a borrowing thread, wherein the Evictor initiates a makeObject in ensureMinIdle and before the newly created object is placed in the pool, the borrowing thread initiates another makeObject that makes the number of instances in circulation = maxActive + 1.   
> This issue does not affect pool 1.3, since addObject is syncrhonized in that version.  It does affect 1.4-RC1 (unreleased snapshot) and the code currently in the 1.4 release branch.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.