[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2023-07-11 Thread Phil Steitz (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17742216#comment-17742216
 ] 

Phil Steitz commented on POOL-407:
--

Looking more carefully at this, the sequence in the description can happen and 
it is a liveness limitation of the pool.  There are other scenarios that can 
lead to this.  Neither GKOP nor GOP currently have a way to recover from 
factory "outages."  My suggestion to use ensureIdle above is not a good idea 
because it could lead to looping in borrowObject.  

The tests added above are not really testing anything.  You can see in the 
console NPE stack traces that don't cause the Junit tests to fail because the 
runner is not picking them up.  A more complex setup would be needed to catch 
them.  That setup would cause the ones where the factory returns null to fail.  
By design, pool create methods throw NPE when factories return null.  This is 
documented in the javadoc for create, but missing from that of the pool 
methods.  

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2023-01-02 Thread Phil Steitz (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17653705#comment-17653705
 ] 

Phil Steitz commented on POOL-407:
--

Thanks for reporting this with the detailed analysis.  It is a liveness bug.  
One option to consider for a patch would be to modify the code in borrowObject 
to do what returnObject does on validation failures, which is to call 
ensureIdle(1, false).  Need to think carefully about the consequences of adding 
this, but that is what we did to address the dual of this problem on return.

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-08 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17614541#comment-17614541
 ] 

Gary D. Gregory commented on POOL-407:
--

Some of the Javadocs say that throwing an exception is how you signal a "make 
an object" problem. IMO, the framework should no-op on null values from a 
factory but that's not what happens as you discovered. A null is pretty 
useless, so an exception seems appropriate.

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-08 Thread Marten Gajda (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17614535#comment-17614535
 ] 

Marten Gajda commented on POOL-407:
---

So the solution (or correct usage?) is to throw an exception in case the pooled 
can not be created? That's what we ended up doing too, just not in {{wrap}} but 
in {{{}create{}}}.

I think the assumption of the openHAB developers (and probably of 
[~sarthak_eddy] too) was that you can indeed return/wrap a {{null}} object and 
just return {{false}} in {{{}validateObject{}}}. I'm fine with throwing an 
Exception and we'll file a PR in the openHAB project to do so as well.

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-07 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17614290#comment-17614290
 ] 

Gary D. Gregory commented on POOL-407:
--

Hello [~dmfs] 

For your use case, I added the test package 
{{org.apache.commons.pool2.pool407}} which contains a configurable set of test 
classes based on your git repo.

The simplest way to fix your issue is to not create a bogus pooled object by 
updating your factory from:
{code:java}
    @Override
    public PooledObject wrap(final KeyedPool407Fixture 
value) {
        return new DefaultPooledObject<>(value,);
    }
{code:}
to:
{code:java}
    @Override
    public PooledObject wrap(final KeyedPool407Fixture 
value) {
        // Require a non-null value.
        return new DefaultPooledObject<>(Objects.requireNonNull(value, 
"value"));
    }
{code}
One would think that changing the validation method only should work, but the 
following is not enough:
{code:java}
@Override
public boolean validateObject(final String key, final 
PooledObject p) {
// TODO Should this be enough even if wrap() does throw and returns a 
DefaultPooledObject wrapping a null?
return p.getObject() != null;
}
{code:java}


> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-05 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612963#comment-17612963
 ] 

Gary D. Gregory commented on POOL-407:
--

Ah, gotcha. Thanks for the pointer.

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-05 Thread Marten Gajda (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612860#comment-17612860
 ] 

Marten Gajda commented on POOL-407:
---

[~ggregory] the missing classes are in the src/main folder of the project 
[https://github.com/dmfs/POOL-407]

I probably can file a PR by the end of the week.

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-04 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612791#comment-17612791
 ] 

Gary D. Gregory commented on POOL-407:
--

[~dmfs] 

Please provide your test as a GitHub PR as it currently does not look like it 
would even compile since there is no Foo or FooPool types in your example 
folder. We need a failing test to debug ;)

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-09-28 Thread Marten Gajda (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17610719#comment-17610719
 ] 

Marten Gajda commented on POOL-407:
---

I think we hit the same or at least a very similar bug. In our case the create 
method of the Object Factory returned {{null}} because the connection that was 
supposed to be established failed at a very early stage.

I've prepared a test case at 
https://github.com/dmfs/POOL-407/blob/main/src/test/java/org/example/FooPoolTest.java

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-08-10 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17577928#comment-17577928
 ] 

Gary D. Gregory commented on POOL-407:
--

Ping?

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-07-25 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17570843#comment-17570843
 ] 

Gary D. Gregory commented on POOL-407:
--

Can you provide a PR with a failing unit test?

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {quote}p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>      p = this.create();
>      if (p != null) {
>         create = true;
>       }
> }
> {quote}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {quote}if (blockWhenExhausted) {
>    if (p == null) {
>       if (borrowMaxWaitMillis < 0L) {
>            p = (PooledObject)this.idleObjects.takeFirst();
>       } else {
>            p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>       }
>    }
>    if (p == null) {
>       throw new NoSuchElementException("Timeout waiting for idle object");
>    }
> }
> {quote}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {quote}private void destroy(PooledObject toDestroy) throws Exception {
>      toDestroy.invalidate();
>      this.idleObjects.remove(toDestroy);
>      this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>      try {
>         this.factory.destroyObject(toDestroy);
>      } finally {
>         this.destroyedCount.incrementAndGet();
>         this.createCount.decrementAndGet();
>      }
> }
> {quote}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {quote}public E takeFirst() throws InterruptedException {
>    this.lock.lock();
>    Object var2;
>    try {
>       Object x;
>       while((x = this.unlinkFirst()) == null) {
>          this.notEmpty.await();
>       }
>       var2 = x;
>     } finally {
>       this.lock.unlock();
>     }
>     return var2;
> }
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-07-25 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17570841#comment-17570841
 ] 

Gary D. Gregory commented on POOL-407:
--

What is "Unknown macro"?

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {quote}p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>      p = this.create();
>      if (p != null) {
>         create = true;
>       }
> }
> {quote}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {quote}if (blockWhenExhausted) {
>    if (p == null) {
>       if (borrowMaxWaitMillis < 0L) {
>            p = (PooledObject)this.idleObjects.takeFirst();
>       } else {
>            p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>       }
>    }
>    if (p == null) {
>       throw new NoSuchElementException("Timeout waiting for idle object");
>    }
> }
> {quote}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {quote}private void destroy(PooledObject toDestroy) throws Exception {
>      toDestroy.invalidate();
>      this.idleObjects.remove(toDestroy);
>      this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>      try {
>         this.factory.destroyObject(toDestroy);
>      } finally {
>         this.destroyedCount.incrementAndGet();
>         this.createCount.decrementAndGet();
>      }
> }
> {quote}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {quote}public E takeFirst() throws InterruptedException {
>    this.lock.lock();
>    Object var2;
>    try {
>       Object x;
>       while((x = this.unlinkFirst()) == null) {
>          this.notEmpty.await();
>       }
>       var2 = x;
>     } finally {
>       this.lock.unlock();
>     }
>     return var2;
> }
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)