Bug #66434 | mysql_library_end does not cleanup properly on Windows | ||
---|---|---|---|
Submitted: | 17 Aug 2012 14:25 | Modified: | 20 Aug 2012 20:57 |
Reporter: | Vyacheslav Chernyshev | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S2 (Serious) |
Version: | 5.5.27 64bit | OS: | Windows (Windows 7 HP 64bit) |
Assigned to: | CPU Architecture: | Any |
[17 Aug 2012 14:25]
Vyacheslav Chernyshev
[17 Aug 2012 16:00]
MySQL Verification Team
Thank you for the bug report. From the Manual: http://dev.mysql.com/doc/refman/5.5/en/connector-cpp-installation-source-windows.html Note Please note the only compiler formally supported for Windows is Microsoft Visual Studio 2003 and above.
[17 Aug 2012 16:44]
Vyacheslav Chernyshev
Hello Miguel. I know, but it really does not matter here as pthread layer on windows is using native WinAPI calls. I can write the code that uses windows-specific constructs and reproduces the same problem. Here it is (can be compiled by both MinGW and MSVC): #include <winsock2.h> #include <windows.h> #include <mysql.h> int main(int argc, char *argv[]) { mysql_library_init(0, NULL, NULL); mysql_library_end(); ExitThread(0); } ExitThread(0) in main causes application to wait till all other threads terminate and it does not happen.
[20 Aug 2012 20:57]
Vyacheslav Chernyshev
After digging through assembly of WinSock-related DLLs I have to admit that it is not a bug of MySQL. I'd like to explain the reason of such behaviour, just in case that somebody else will find the same issue. getservbyname("mysql", "tcp") is called during initialization of MySQL library. On Windows it is using WSA-specific service lookup functions (WSALookupServiceBegin, WSALookupServiceNext, WSALookupServiceEnd) internally. At first usage they trigger loading of namespace provider DLLs and one of them spawns this helper thread. Unfortunately it is not shut down when WSACleanup is called, so I'll have to workaround this problem myself.