Bug #105606 SQLCancel and other API functions are not thread safe
Submitted: 16 Nov 2021 21:52 Modified: 1 Jun 2022 17:15
Reporter: Pierre le Riche Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:8.0.27 OS:Windows
Assigned to: CPU Architecture:Any

[16 Nov 2021 21:52] Pierre le Riche
Description:
Calling SQLCancel on a statement that is busy executing on another thread causes intermittent crashes in the MySQL ODBC driver. This is not consistent with the documentation for the SQLCancel call, see https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlcancel-function?view=sql-ser...

Note the following excerpt from the above, particularly the last line:
"SQLCancel can cancel the following types of processing on a statement:
A function running asynchronously on the statement.
A function on a statement that needs data.
A function running on the statement on another thread."

It should therefore be possible to call SQLCancel on a statement handle "owned" by another thread (like it is with Microsoft SQL Server and others).

How to repeat:
Open a statement, bind columns and fetch data on one thread. Simultaneously from a second thread call SQLCancel to cancel the execution of the statement on the first thread. Repeat several times until the driver crashes.

See https://bugs.mysql.com/bug.php?id=91951 for a similar bug report, with a test case.

Suggested fix:
SQLCancel should be made thread safe, as it is documented to be.
[22 Feb 2022 14:03] MySQL Verification Team
Hello,

Thank you for the bug report and feedback.

Regards,
Ashwini Patil
[11 Mar 2022 8:48] Rafal Somla
Posted by developer:
 
While looking at this issue we discovered that we have more functions in ODBC API which work on statement handles that are not protected against concurrent access from multiple threads. We need a more systematic solution that will fix this problem in general.
[30 May 2022 7:01] Bogdan Degtyariov
Posted by developer:
 
The issue with the thread safety of SQLCancel() and other ODBC functions is fixed in the version 8.0.30.
[1 Jun 2022 17:15] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/ODBC 8.0.30 release, and here's the proposed changelog entry from the documentation team:

SQLCancel() was not thread safe; it and other ODBC API functions are now
thread safe.

Thank you for the bug report.