From: Vladislav Vaintroub Date: September 1 2008 6:17pm Subject: bzr push into mysql-5.1 branch (vvaintroub:2727 to 2729) Bug#33031 Bug#37226 List-Archive: http://lists.mysql.com/commits/53018 X-Bug: 33031,37226 Message-Id: <200809011817.m81IH6QI017239@mail.mysql.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 2729 Vladislav Vaintroub 2008-09-01 Bug#37226 Explicit call of my_thread_init() on Windows for every new thread. Bug#33031 app linked to libmysql.lib crash if run as service in vista under localsystem There are some problems using DllMain hook functions on Windows that automatically do global and per-thread initialization for libmysqld.dll 1)per-thread initialization(DLL_THREAD_ATTACH) MySQL internally counts number of active threads that and causes a delay in in my_end() if not all threads are exited. But,there are threads that can be started either by Windows internally (often in TCP/IP scenarios) or by user himself - those threads are not necessarily using libmysql.dll functionality, but nonetheless the contribute to the count of open threads. 2)process-initialization (DLL_PROCESS_ATTACH) my_init() calls WSAStartup that itself loads DLLs and can lead to a deadlock in Windows loader. Fix is to remove dll initialization code from libmysql.dll in general case. I still leave an environment variable LIBMYSQL_DLLINIT, which if set to any value will cause the old behavior (DLL init hooks will be called). This env.variable exists only to prevent breakage of existing Windows-only applications that don't do mysql_thread_init() and work ok today. Use of LIBMYSQL_DLLINIT is discouraged and it will be removed in 6.0 modified: libmysql/dll.c 2728 Vladislav Vaintroub 2008-09-01 [merge] (no message) 2727 Vladislav Vaintroub 2008-09-01 [merge] merge removed: mysql-test/suite/rpl/t/rpl_view-slave.opt modified: mysql-test/extra/rpl_tests/rpl_log.test mysql-test/suite/rpl/r/rpl_row_log.result mysql-test/suite/rpl/r/rpl_row_log_innodb.result mysql-test/suite/rpl/r/rpl_stm_log.result mysql-test/suite/rpl/t/rpl_stm_log-slave.opt === modified file 'libmysql/dll.c' --- a/libmysql/dll.c 2008-02-19 17:45:11 +0000 +++ b/libmysql/dll.c 2008-09-01 18:04:17 +0000 @@ -89,9 +89,20 @@ BOOL APIENTRY LibMain(HANDLE hInst,DWORD UNREFERENCED_PARAMETER(lpReserved); } /* LibMain */ + +static BOOL do_libmain; int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved) { - return LibMain(hInst,ul_reason_being_called,lpReserved); + /* + Unless environment variable LIBMYSQL_DLLINIT is set, do nothing. + The environment variable is checked once, during the first call to DllMain() + (in DLL_PROCESS_ATTACH hook). + */ + if (ul_reason_being_called == DLL_PROCESS_ATTACH) + do_libmain = (getenv("LIBMYSQL_DLLINIT") != NULL); + if (do_libmain) + return LibMain(hInst,ul_reason_being_called,lpReserved); + return TRUE; } #elif defined(WINDOWS)