Bug #103968 | C++, odbc, using multi-threaded access to mysql database crash | ||
---|---|---|---|
Submitted: | 10 Jun 2021 8:10 | Modified: | 12 Nov 2021 12:59 |
Reporter: | Bob Lee | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | Connector / ODBC | Severity: | S3 (Non-critical) |
Version: | comunity 8.0.21 and comunity 5.7.32 | OS: | Windows (windows 10 家庭中文版) |
Assigned to: | MySQL Verification Team | CPU Architecture: | Any |
Tags: | C++, multithread, ODBC |
[10 Jun 2021 8:10]
Bob Lee
[10 Jun 2021 8:16]
Bob Lee
This is the screenshot when the error occurred
Attachment: 屏幕截图(304).png (image/png, text), 190.36 KiB.
[10 Jun 2021 8:31]
Bob Lee
because I have a CRichEditCtrl ctrl in the window,it is initialized by: AfxInitRichEdit2(); AfxEnableControlContainer(); ::AfxOleInit(); the AfxOleInit() function contains the function CoInitialize(),so that it is no need to add the function CoInitializeEx() to initialize ado driver
[1 Jul 2021 6:08]
Bob Lee
Please connect to two mysql servers at the same time in the sample project, after a period of time (sometimes a few hours, sometimes a few days), the problem will appear
[12 Oct 2021 12:59]
MySQL Verification Team
Hello Bob Lee, Thank you for the details. It seems that the zip folder containing project details missing some of the information. Please attach complete test case and steps to reproduce this issue at our end. Regards, Ashwini Patil
[13 Nov 2021 1:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".
[22 Jan 2024 15:32]
Shlomo Margalit
I recreated the problem on my machine (mysql 8.0.30 driver) using 4 threads that constantly connect to the same mysql server, disconnect from the server, and then wait 100 milliseconds. the problem is in mysql_client_plugin_init, the function may be called twice by 2 different threads, this causes the plugin list to contain the same plugins twice (maybe more in some scenarios). because the plugin sha256_password is in the plugin list twice, mysql_client_plugin_deinit will call its deinit twice, causing the mutex g_public_key_mutex to be used after it was already destroyed. please note that in addition to this problem mysql_client_plugin_init memsets the plugins array outside the LOCK_load_client_plugin mutex, this can also cause problems.
[22 Jan 2024 21:15]
Shlomo Margalit
a good solution for this could be to take the initialzation code from mysql-server/libmysql/libmysql.cc, function mysql_server_init and create a class that runs it in the constructor, then creating a static instance of it will be guaranteed to be thread safe and run only once by the c++ 11 and above standard. the code that initializes the thread by calling my_thread_init should be executed always, it doesn't do anything if the thread is already initialized.