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

TDSParser stuck on TDS_COLMETADATA #1661

Closed
mmimica opened this issue Sep 28, 2021 · 2 comments · Fixed by #1662
Closed

TDSParser stuck on TDS_COLMETADATA #1661

mmimica opened this issue Sep 28, 2021 · 2 comments · Fixed by #1662
Assignees
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.

Comments

@mmimica
Copy link
Contributor

mmimica commented Sep 28, 2021

Driver version

9.4.0.jre11

SQL Server version

Microsoft SQL Server 2019 (RTM-CU11) (KB5003249) - 15.0.4138.2 (X64)

Client Operating System

Linux

JAVA/JVM version

16

Table schema

Problem description

SQLServerStatement.close() is stuck in an infinite loop.

   ...
   com.microsoft.sqlserver.jdbc.TDSTokenHandler.onColMetaData line: 256 
   com.microsoft.sqlserver.jdbc.TDSParser.parse line: 109 
   com.microsoft.sqlserver.jdbc.TDSParser.parse line: 37 
   com.microsoft.sqlserver.jdbc.TDSParser.parse line: 26 
   com.microsoft.sqlserver.jdbc.SQLServerStatement.processExecuteResults line: 1317 
   com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtBatchExecCmd.processResponse line: 2700 
   com.microsoft.sqlserver.jdbc.TDSCommand.close line: 7487 
   com.microsoft.sqlserver.jdbc.SQLServerStatement.discardLastExecutionResults line: 147 
   com.microsoft.sqlserver.jdbc.SQLServerStatement.closeInternal line: 676 
   com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.closeInternal line: 337 
   com.microsoft.sqlserver.jdbc.SQLServerStatement.close line: 691 
   ...

This is a code snipped from TDSCommand::close()

        while (!processedResponse) {
            try {
                processResponse(tdsReader);
            } catch (SQLServerException e) {
                if (logger.isLoggable(Level.FINEST))
                    logger.finest(this + ": close ignoring error processing response: " + e.getMessage());

                if (tdsReader.getConnection().isSessionUnAvailable()) {
                    processedResponse = true;
                    attentionPending = false;
                }
            }
        }

It loops while processedResponse is false. The TDSParser::parse() sets processedResponse=true only on end-of-stream. It never reaches end-of-stream because it bails out on tdsTokenHandler.onColMetaData(tdsReader); without reading the token (it only peeks).

JDBC trace logs

Sep 28, 2021 8:04:15 AM com.microsoft.sqlserver.jdbc.TDSTokenHandler onColMetaData
SEVERE: ConnectionID:7225 ClientConnectionId: 5bfa6ef7-b0af-4c8d-b832-0e04a50e286a: batch completion: Encountered TDS_COLMETADATA (0x81). SHOWPLAN is ON, ignoring.
mmimica pushed a commit to mmimica/mssql-jdbc that referenced this issue Sep 28, 2021
mmimica pushed a commit to mmimica/mssql-jdbc that referenced this issue Sep 28, 2021
@mmimica
Copy link
Contributor Author

mmimica commented Sep 28, 2021

introduced in #666

@lilgreenbird
Copy link
Contributor

hi @mmimica

Thank you for reporting this. As you mentioned this bug was inadvertently introduced in PR #666 to address issue #661. We have this in our backlog as this requires more investigation to come up with a fix that does not break the issue it was trying to fix. So this issue is in the backlog to be triaged along with other bugs and features when we plan for the next semester.

I saw that you created PR #1662 but unfortunately before we could review and merge it you would need to add junit tests and we would also need to verify that it does not break the old issue.

@lilgreenbird lilgreenbird added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Oct 12, 2021
@lilgreenbird lilgreenbird linked a pull request Nov 23, 2021 that will close this issue
VeryVerySpicy added a commit that referenced this issue Nov 23, 2021
* try to solve #1661

* Update tdsparser.java

Fine tuned fix.

* Update tdsparser.java

Updated formatting

Co-authored-by: Milan Mimica <milan.mimica@infobip.com>
Co-authored-by: Wei Zhang <53021889+v-zhangw@users.noreply.github.com>
lilgreenbird pushed a commit to lilgreenbird/mssql-jdbc that referenced this issue Dec 1, 2021
* try to solve microsoft#1661

* Update tdsparser.java

Fine tuned fix.

* Update tdsparser.java

Updated formatting

Co-authored-by: Milan Mimica <milan.mimica@infobip.com>
Co-authored-by: Wei Zhang <53021889+v-zhangw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants