Hibernate/c3p0 connection leak

柔情痞子 提交于 2019-12-04 03:00:30

I doubt that Hibernate or Spring are leaking connections, I suspect a configuration problem somewhere that is making your application running our of connections. Here is what I would do:

  • Lower the number of concurrent users and the pool size, I'm not sure the problem is load related.

  • Set unreturnedConnectionTimeout to a value greater than 0 in combination with debugUnreturnedConnectionStackTraces to true to figure out where Connections are being checked-out and not returned to the pool and post some of the generated stacktrace.

  • Identify one business flow (one use case scenario) on which the problem occurs and run your test on this scenario only until you find out the problem.

Also, I'd update the question with one or two stacktraces, maybe someone will spot something obvious.

Hibernate and Spring are not the ones leaking connections, somewhere in your app is leaking. I'm not sure about C3P0 but BoneCP (http://jolbox.com) has support to detect unclosed connections (and give you stack traces of where you opened them) + will close off any leaking connections for you when a thread dies off without proper cleanup.

this post describes how to debug c3p0 connection leak issue using the parameters and stacktrace. Hope this helps

Justas

Query your database:

select * from pg_stat_activity;

And check which queries are long lasting with idle in transaction status. Try to locate them in your code and research why transaction is not completed.


Few things to check in a code/configuration:

  • Commit transactions explicitly or use @Transactional. Please note that @Transactional works only for public methods.

  • If you're using Hibernate 5.1.0.Final, then persistence.xml should contain:

<property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider" />

Instead of:

<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />

  • If you're using

<property name="hibernate.enable_lazy_load_no_trans" value="true" />

it may cause connection leaks when lazy loading. Related discussions:


Check related articles:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!