-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It didn't reach the limit of max-pool-size, but there was an maxPoolSize exhausted exception #23483
Comments
Hi,can anyone give some thoughts on this issue? |
The jdbc connection pool still has space to create new connections, but the request failed because of this problem(failed to get connection). |
This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment |
This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment |
…ty fix by using a lock between two methods to ensure they are not called at the same time. Also shows in a unit test the problem of not calling notifyWaitingThreads when connection problems occurred.
I have written a unit test to try and reproduce this behavior. About reported item 1 and 2
See attached test case: Line 272 does not fail when I make sure that freeUnenlistedResource and getResourceFromPool are never called at the same moment. See hack in line 1106 of the attached altered ConnectionPool class and the console output. Undo the lock and the console output shows the random behaviour of adding resources to the pool, while threads should wait for one to become available in the pool because pool is maxed out.
Note: I also tested with the old /connectors-runtime/src/main/java/com/sun/enterprise/resource/pool/datastructure/ListDataStructure.java instead of the RWLockDataStructure. Both show the same behaviour. Example log of succesful test with max pool size 5 and resize with 1:
Failing output (without a fix / using current ConnectionPool code):
About reported item 3 Branch with unit tests: |
…better max pool size logic. Add lock, add notifyWaitingThreads call for better max pool size logic. No longer getResources while the pool is being resized. And inform waiting threads when resources are marked as failed.
…better max pool size logic. Fix incorrect javadoc.
Fixes #23483 Add lock, add notifyWaitingThreads call for better max pool size logic.
Hi!
We hava an application that uses jdbc connection pooling.And uses the following settings:
max-pool-size:200
pool-resize-quantity:2
max-wait-time-in-millis:5000
It has been working fine for a long time, but recently we get the following exception while trying to concurrently access.
[java.sql.SQLException:Error in allocating a connection. Cause: In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections.]
The number of concurrent requests is 100.
Actually,It didn't exceed the limit of max-pool-size 200.
By analyzing the ConnectionPool code,we find a problem in ConnectionPool#resizePoolAndGetNewResource.
In order to understand the problem simply,suppose uses the following settings:
max-pool-size:10
pool-resize-quantity:1
max-wait-time-in-millis:5000
and,the problem flow is as follows:
now there are five connections in the jdbc connection pool and all these connections are in-used
one request comes to get connection(by Thread A)
because there's still space to create a connection(current connections < max-pool-size),
Thread A starts to execute the following resizePoolAndGetNewResource.
In **1 method create 1 new connection, and add connection to connection pool.
thread A before executing **2 method (take the connection off from connection pool)
thread B just comes to get connection,and just takes the connection off from connection pool.
when thread A executes **2 method,the connection was tooken by thread B, returns null.
and max-wait-time-in-millis is timeout,in **3 method,the error will happen.
[java.sql.SQLException:Error in allocating a connection. Cause: In-use connections equal max-pool-size and expired max-wait-time. Cannot allocate more connections.]
Environment Details
Questions about this case
Now,we hava one question:
When a thread execute the resizePoolAndGetNewResource, should this thread get the connection first?
If YES,the code of resizePoolAndGetNewResource has a bug.
If NO,the error message [Cause: In-use connections equal max-pool-size and expired max-wait-time.] is not right.
Related source
com.sun.enterprise.resource.pool.ConnectionPool
The text was updated successfully, but these errors were encountered: