Microsoft driver does not time out during connection validation using JDBC4ValidConnectionChecker in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Microsoft SQL Server JDBC Driver
Issue
-
Observing hangs during connection validation (of externally terminated connections) when using the
JDBC4ValidConnectionCheckervalidation class. -
A series of thread dumps collected over a minute or more show the same (unchanging) stack trace:
java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) ... at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7417) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3488) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:262) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:237) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQueryInternal(SQLServerStatement.java:722) at com.microsoft.sqlserver.jdbc.SQLServerConnection.isValid(SQLServerConnection.java:6122) at org.jboss.jca.adapters.jdbc.extensions.novendor.JDBC4ValidConnectionChecker.isValidConnection(JDBC4ValidConnectionChecker.java:58) at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory.isValidConnection(BaseWrapperManagedConnectionFactory.java:1285)
Resolution
Contact Microsoft Support for specific recommendations.
As per Content from github.com is not included.this bug report, Microsoft advised using socketTimeout parameter in the connection url to avoid the hang, e.g.:
jdbc:sqlserver://<DBSERVER>;databaseName=<DBNAME>;instanceName=<INSTANCE_NAME>;socketTimeout=20
Root Cause
Disclaimer: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.
- Content from github.com is not included.By default, the timeout Content from github.com is not included.provided to the Content from docs.oracle.com is not included.Connection.isValid(int) invocation is 5 (seconds).
- Analysis indicates that the driver is not able to enforce the timeout provided using the
Connection.isValid(int)API.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.