Skip to content
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

MSSQL Server connection goes to sleeping state and blocking another queries #2231

Closed
ravirajsinh-lab opened this issue Aug 24, 2024 · 3 comments

Comments

@ravirajsinh-lab
Copy link

ravirajsinh-lab commented Aug 24, 2024

I am encountering an issue with a sleeping connection in MSSQL production server. My application is a multi-tenant application that connects to 6 databases and has 30 Tomcat instances. I have used the following libraries:

  • JDK: Azul 11.0.12.0.101
  • Apache Tomcat/9.0.54
  • Mssql Driver Version 12.8.0.jre11
  • HikariCP Version 5.1.0 (latest)

Hikari cp config

  • "maxLifetime": 1320000,
  • "idleTimeout": 238000,
  • "connectionTimeout": 30000,
  • "minimumIdle": 5,
  • "maximumPoolSize": 10,
  • "keepaliveTime": 30000,
  • "connectionTestQuery": "IF @@TRANCOUNT > 0 ROLLBACK TRAN", // added this test query, but still not working.
  • "leakDetectionThreshold": 60000
  • "dataSource.ConnectRetryCount": 5,
  • "dataSource.ConnectRetryInterval": 5,
  • "dataSource.queryTimeout": 1200,
  • "dataSource.cancelQueryTimeout": 300,
  • "dataSource.lockTimeout": 1500000,
  • "dataSource.socketTimeout": 1500000,

I have attempted to adjust the above Hikari pool configuration multiple times, but I am still receiving the sleeping connection issue, which is causing other queries to become blocked. When checking sp_whoisactive in the MSSQL server, I can see that sessions are in sleeping states for hours. It appears that HikariCP is not closing connections properly.

During my investigation of the HikariCP code, I discovered that in the method PoolBase.quietlyCloseConnection, it attempts to close connections. However, I found that it sets the NetworkTimeout hardcoded to 15 seconds. This leads me to question whether this shorter timeout is causing the connections to not be closed properly.

Can you provide any assistance? Thank you in advance.

Note: There is an Azure gateway between the application and database.

@ravirajsinh-lab
Copy link
Author

@brettwooldridge can you please help here?

@quaff
Copy link
Contributor

quaff commented Sep 27, 2024

@ravirajsinh-lab I created #2247 to allow configuring closeTimeout.

@brettwooldridge
Copy link
Owner

This should be resolvable by configuring the socket timeout for your driver and ensuring that keepalive is properly configured, see Connection Recovery for MSSQL. I do recommend configuring keepalive at the OS level, regardless of what drivers say they support, see Setting OS TCP Keepalive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants