Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 937A6D59E for ; Fri, 30 Nov 2012 16:04:03 +0000 (UTC) Received: (qmail 27968 invoked by uid 500); 30 Nov 2012 16:04:01 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 27823 invoked by uid 500); 30 Nov 2012 16:04:01 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 27525 invoked by uid 99); 30 Nov 2012 16:04:00 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Nov 2012 16:04:00 +0000 Date: Fri, 30 Nov 2012 16:04:00 +0000 (UTC) From: "Bruno Candido Volpato da Cunha (JIRA)" To: issues@commons.apache.org Message-ID: <1572880560.45481.1354291440411.JavaMail.jiratomcat@arcas> In-Reply-To: <1836070425.29542.1332960568504.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Comment Edited] (POOL-213) _numActive can go negative MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/POOL-213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13507394#comment-13507394 ] Bruno Candido Volpato da Cunha edited comment on POOL-213 at 11/30/12 4:03 PM: ------------------------------------------------------------------------------- Hello. I am having this problem in Commons-Pool 1.6 too... When I return an Object that doesn't exist in Pool (or even when I return a null), the numActive go negative. {code:title=Test.java|borderStyle=solid} @Test public void testCommonsPool() { GenericObjectPool pool = ProgressConnectionManager.getInstance().getPool(); System.out.println(pool.getNumActive()); try { ProgressConnection conn = pool.borrowObject(); pool.returnObject(null); pool.returnObject(null); } catch(Exception e) { e.printStackTrace(); } System.out.println(pool.getNumActive()); } {code} The result that I get is: 0 1 was (Author: brunocvcunha): Hello. I am having this problem in Commons-Pool 1.6 too... When I return an Object that doesn't exist in Pool (or even when I return a null), the numActive go negative. {code:title=Test.java|borderStyle=solid} @Test public void testCommonsPool() { GenericObjectPool pool = ProgressConnectionManager.getInstance().getPool(); System.out.println(pool.getNumActive()); try { ProgressConnection conn = pool.borrowObject(); pool.returnObject(null); pool.returnObject(null); } catch(Exception e) { e.printStackTrace(); } System.out.println(pool.getNumActive()); } {code} The result that I get is: 0 1 > _numActive can go negative > -------------------------- > > Key: POOL-213 > URL: https://issues.apache.org/jira/browse/POOL-213 > Project: Commons Pool > Issue Type: Bug > Affects Versions: 1.5.4 > Reporter: Mark Mindenhall > > I'm working on a project that uses Hector (Cassandra client). Hector uses commons-pool (we're using 1.5.4) to pool connections to hosts within a Cassandra cluster. Hector provides a JMX MBean that exposes a "NumActive" property, which is the cumulative call to retrieve numActive from all of the individual connection pools. When querying this property via JMS on our production servers, we often see negative values. For example, on a server that has three connection pools, the "NumActive" property reported was -3899. > I know this issue has been reported before (POOL-29), and was supposedly fixed. The fix discussed there was to merely check the value of _numActive to prevent it from going negative. However, that does not fix the real problem here, which is that it is possible to decrement _numActive more than once for each activated object. > For example, from a quick look at the code (GenericObjectPool.java, v1.5.4), it would be possible to do the following: > 1) Create a pool with 10 objects. > 2) Borrow all 10 objects from the pool. > 3) Call getNumActive (returns 10). > 4) Call invalidateObject for ONE of the objects 11 times. > 5) Call getNumActive (returns -1). > The invalidateObject method calls the _factory to destroy the object, and subsequent calls to destroy the same object may or may not result in an exception. Regardless, _numActive is decremented within a finally block, and therefore would always be decremented even if the object had already been invalidated and destroyed. > I'd like to suggest using a HashSet instead of a counter to keep track of active objects. If borrowing an object added it to a HashSet, and returning or invaliding the object removed it from the HashSet (subsequent removes would be no-ops), the example given above would not result in an incorrect value when getNumActive is called (it would just return the current size of the HashSet). > Note that although unrelated to this bug, it might also be wise to use a HashSet instead of the int counter _numInternalProcessing. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira