-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Connections not closed on Shutdown #76
Comments
Thanks for finding this. I'll add a unit test and work on a fix. |
If you don't mind, it would be great if you can test the 1.3.9-SNAPSHOT build to see if your issue is fixed (after removing your sleep call). git clone https://github.com/brettwooldridge/HikariCP.git Then use 1.3.9-SNAPSHOT as a maven dependency or use the jar from the target directory. |
Thank you for the quick response. I have tested the new version. 2 remarks:
I have looked into the thread leak problem. I think the cause is, that the "filler"/AddConnection-Thread (create in A working fix has been to add a I have tried to create a pull request with an added test case for the thread leak and a possible fix. I am new to this github thing, so I hope I haven't messed up. :) |
Fix #76 avoid possible thread leak on shutdown. Thanks.
There seems to be a race condition when a pool is created and immediately shutdown, that leaves connections open.
Tested with HikariCP 1.3.8 and "PostgreSQL 9.3.4, compiled by Visual C++ build 1600, 64-bit". DataSource is
org.postgresql.ds.PGSimpleDataSource
.To reproduce create a HikariDataSource and shut it down immediately. Querying the number of open connections afterward
SELECT count(*) FROM pg_stat_activity;
shows 21 (20 is the my configured Hikari pool size). Its sufficient to sleep for a second before shuting down to make the problem go away.The problem might be in line 354 in
com.zaxxer.hikari.pool.HikariPool
. The methodcloseIdleConnections
as its name indicates closes only idle connections. If one sets a conditional break point on line 355 with the conditionlist.size() != connectionBag.size()
one sees the the list of idle connections is empty and the list of connections has size 20. I am not sure what the strategy is for closing 'non-idle' connections on pool shutdown.To give some context I run into this problem when a test suite started failing yesterday (too many open connections db error) . The tests of course do not close pools immediately after creating them, that is just for reproduceing the problem. They might however run just a few statements before closing a pool. I am also wondering if a connection might be left open, when it used before the pool is shut down. It might be non-idle at that point?
Thanks a lot for your impressing work. Hope this helps.
The text was updated successfully, but these errors were encountered: