# Multi threads + Hibernate (ERROR: Connection leak detected: there are 1 unclosed)

**URL:** <https://discourse.hibernate.org/t/multi-threads-hibernate-error-connection-leak-detected-there-are-1-unclosed/3382>\
**Category:** Hibernate ORM\
**Created:** [October 22, 2019, 4:07pm UTC](https://discourse.hibernate.org/t/multi-threads-hibernate-error-connection-leak-detected-there-are-1-unclosed/3382 "2019-10-22T16:07:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ipgaero](https://avatars.discourse-cdn.com/v4/letter/i/e495f1/32.png) [@ipgaero](https://discourse.hibernate.org/u/ipgaero)\
**Post date:** [October 22, 2019, 4:07pm UTC](https://discourse.hibernate.org/t/multi-threads-hibernate-error-connection-leak-detected-there-are-1-unclosed/3382/1 "2019-10-22T16:07:35Z")

</div>

Hello  
I use multi threads to create long request to database. Each thread starts processing with opening single session sessionFactory.openSession() I manually create exceptional situation by shutting down Application during working processes in background. I get the log error "ERROR: Connection leak detected: there are 1 unclosed connections upon shutting down pool "

What is the right way to process this exceptional situation ?

I`ve tried sessionFactory.getCurrentSession().close(); it does not help. Actually I`d like to know how to manage case if I have multi threads each has a session working in background?!

Next thing is even if I have multy threads each has a session working in background I get log error only about 1 unclosed connection, despite I`m observing many connections in database  
Why log says only one connection ?

Igor

---

<div class="post-metadata">

**Author:** ![p3consulting](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/p3consulting/32/565_2.png) [@p3consulting](https://discourse.hibernate.org/u/p3consulting)\
**Post date:** [January 15, 2020, 5:39am UTC](https://discourse.hibernate.org/t/multi-threads-hibernate-error-connection-leak-detected-there-are-1-unclosed/3382/2 "2020-01-15T05:39:01Z")

</div>

May be it’s not one of yours… but one used by the framework… to ping the health of the db…
