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 2019/10/03 00:52:00 UTC

[jira] [Commented] (POOL-326) Threading issue, NullPointerException and IllegalStateException in GenericKeyedObjectPool

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

Phil Steitz commented on POOL-326:
----------------------------------

I think I found the root cause of this issue.  In destroy, we use the following to test if an object is idle in the pool (so can be destroyed if the "always" parameter is false)
{code:java}
final boolean isIdle = objectDeque.getIdleObjects().remove(toDestroy);
{code}
But we don't check its state, which leaves open the possibility that it can be in process of being considered for eviction.  This can result in its getting destroyed twice - once by say clearOldest and then a second time by the evictor.  That results in the createCount going prematurely to 0, which is what causes the keyed pool to be removed before it has no objects under management.  

> Threading issue, NullPointerException and IllegalStateException in GenericKeyedObjectPool
> -----------------------------------------------------------------------------------------
>
>                 Key: POOL-326
>                 URL: https://issues.apache.org/jira/browse/POOL-326
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 2.4.2
>            Reporter: Chris Allison
>            Priority: Major
>             Fix For: 2.6.1
>
>         Attachments: ObjectPoolIssue.java, pool-326.patch
>
>
> I'll included a test to help reproduce this issue.  Take a look at the embedded comments as it's extremely difficult to reproduce.  I've seen the provided test show the failure on more than one PC so I believe it will show the problem.
> Example stack trace for error on return:
> java.util.concurrent.ExecutionException: java.lang.NullPointerException
> 	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
> 	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
> 	at threading_pool.ObjectPoolIssue.run(ObjectPoolIssue.java:63)
> 	at threading_pool.ObjectPoolIssue.main(ObjectPoolIssue.java:23)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
> Caused by: java.lang.NullPointerException
> 	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.returnObject(GenericKeyedObjectPool.java:474)
> 	at threading_pool.ObjectPoolIssue$Task.call(ObjectPoolIssue.java:112)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	at java.lang.Thread.run(Thread.java:745)
> Example stack trace for error on borrow:
> java.util.concurrent.ExecutionException: java.lang.NullPointerException
> 	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
> 	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
> 	at threading_pool.ObjectPoolIssue.run(ObjectPoolIssue.java:63)
> 	at threading_pool.ObjectPoolIssue.main(ObjectPoolIssue.java:23)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
> Caused by: java.lang.NullPointerException
> 	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.deregister(GenericKeyedObjectPool.java:1146)
> 	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:438)
> 	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:279)
> 	at threading_pool.ObjectPoolIssue$Task.call(ObjectPoolIssue.java:108)
> 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	at java.lang.Thread.run(Thread.java:745)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)