microsoft/mssql-jdbc

logon is retried if user cannot open database

dcolazin opened this issue · 4 comments

Driver version

Tested both on 12.4.2 and 12.6.0.

SQL Server version

SQL Server 2019

Client Operating System

Windows 10

JAVA/JVM version

openjdk 17.0.2

Table schema

irrelevant

Problem description

If the given user exists but is not authorized to open the database, login is repeated.

Expected behavior

If the given user exists but is not authorized to open a database, login should not be repeated and an exception should be thrown.

Actual behavior

If the given user exists but is not authorized to open the database, login is repeated. From a first glance looking at the debugger, connection pool is exhausted and the last connection is used to retry the login. We receive a SQLServerException with errorCode 4060 (but the detailMessage is unquestionable: Cannot open database "ABC" requested by the login. The login failed. ClientConnectionId:uuid) which is not correctly handled. Retries repeats until timer expiration.

Moreover, the actual exception might be masked by other driver timeouts.

Error message/stack trace

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "ABC" requested by the login. The login failed. ClientConnectionId:uuid 
	at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:304)
	at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:137)
	at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:42)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:6612)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:5154)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:5087)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7675)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4137)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:3583)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:3172)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:3014)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1836)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1246)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
	... 17 common frames omitted

Any other details that can be helpful

--

JDBC trace logs

--

Thanks for your reported issue. We have been recently updating the connection retry logic in the driver and are planning to include these updates in the upcoming JDBC 12.7.1 driver preview release which is happening in the next few days. When available I recommend retrying your problem scenario with the preview to see if that fixes your issue.

Thx,
Barry

I misstated the preview version. You should be looking for JDBC 12.7.0 and not 12.7.1. Please let us know if the preview resolves your retry issue.

Thx,
Barry

Thank you for the fast reply. I will now try to test the 12.7.0 version or the 12.7.1-SNAPSHOT and report back.

Hello again, tested version 12.7.0 and indeed this issue was fixed. Thank you!