-
Notifications
You must be signed in to change notification settings - Fork 426
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
Erroneously inserted rows with statement pooling enabled and when a Connection gets re-used from the ConnectionPool #2356
Comments
thanks for the repro info we'll do some investigation and get back to you. |
thanks for the repro we can see the issue will be implementing a fix for this in the upcoming preview. |
I believe this is happening cos the cache is messed up. If I clear the preparedStatementHandleCache in resetPooledConnection() then this works. I'm just doing some testing now. |
I appreciate you committing the fix. Also this duplicates error may happen in any other scenario where the SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find prepared statement with handle gets thrown due to server side exceptions and in that cases, duplicates is still possible, is it not ? |
Statement pooling is per connection, yes, but sp_reset_connection (resetPooledConnection) clears any prepared statements in the session on the server (among many other cleanup tasks). That's why you see the Could not find prepared statement with handle error. Clearing the cache would keep the driver from re-using invalid prepared statement handles. But I'd be worried that the driver is executing some of the batch or consuming/flushing results on the wrong side of the pool use boundary. ExecuteBatch() should be executing and consuming all the results from the server immediately and I wonder if it's leaving some hanging until the next statement execution (which is happening after the connection goes back into and then comes out of the pool again). |
yes we agree there may be other issues there we will take a closer look into this when we can, thanks |
Hi @lilgreenbird |
The 12.7 preview release is available. The next stable release to include this will either be the 12.6.2 hotfix and/or the 12.8 GA release. We have not finalized a date for the hotfix, but the GA can be expected at the end of July (July 31). |
Driver version
com.microsoft.sqlserver mssql-jdbc 12.6.1.jre11SQL Server version
Client Operating System
Windows 10 Pro
JAVA/JVM version
Java 17
Problem description
There are some duplicate inserts and some missing entries when a custom connection pool is being utilized and server side statement pooling is enabled (using the setDisableStatementPooling flag). When the connection is re-used from the connection pool and the flag
setDisableStatementPooling is set to false
this issue seems to happen.To test this instance, I was able to simulate a very basic stand alone as below :
Please see the following test program, where I intentionally return the previously created connection object from the _userToConnectionsMap cache map for subsequent runs.
This program results in incorrect entries being inserted to the test table with last item of the batch being repeated and the first item of the batch missed out.
Expected behavior
Caching and connection pool shouldn't lead to incorrect insert to the table. Should see no duplicates and no missing rows.
Actual behavior
At the end of the stand alone program run, could see there are (2*j) - 1 = 9 rows instead of 5 rows for column c1 : 2 and (j-1) = 4 entries missing for column c1 : 0
Error message/stack trace
With FINER logging enabled for SQL driver , could see the following exception :
SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find prepared statement with handle
Any other details that can be helpful
This issue does not happen when I comment the call to
sp_reset_connection
in SQLServerPooledConnection.javaJDBC trace logs
SQL Profiler data
The text was updated successfully, but these errors were encountered: