Bug #32850 mysql_thread_init() breaks gcc exception handling
Submitted: 29 Nov 2007 16:21 Modified: 30 Nov 2007 14:21
Reporter: Angus M Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:5.0.26 OS:Linux (Suse 10.2)
Assigned to: CPU Architecture:Any
Tags: exception, gcc, gnu, mysql_thread_init, pthread

[29 Nov 2007 16:21] Angus M
Description:
I created a worker thread, using the pthread library, and also called mysql_thread_init() to make the connection created in the main thread work in the worker thread. When an exception was thrown in the worker thread, it was duly caught by my try-catch block in the worker thread, but it also caused the entire app to terminate. The message in stderr indicated that this was caused by an unhandled exception.
   Incidentally, the main thread was also working inside a try-catch block of its own (including the pthread_create() call) although this is neither here nor there, since exceptions are only supposed to affect the threads in which they are thrown.
   By removing the mysql_thread_init() and replacing it with mysql_init() and mysql_real_connect() I was able to workaround the problem, and exceptions were then handled properly.

I'm using gcc 4.1.2 on an AMD64.

How to repeat:
I should think creating a thread with pthread, then calling mysql_thread_init() and throwing an exception would do it.
[29 Nov 2007 17:01] Valeriy Kravchuk
Thank you for a problem report. Please, send the exact C code that demonstrates the behaviour described. Test it with a newer version of server/libmysqlclient_r.

See http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html also.
[29 Nov 2007 18:04] Angus M
For one thing, the code is not C, it's C++ (does GNU C have exceptions?), and the source code is in the Mb. What's more, the source code belongs to a server, which works with a Windows-based client, which is in even more Mb.
    The latest "general release" source code is for 5.0.45. Is that a new enough version?
[29 Nov 2007 18:31] Valeriy Kravchuk
Yes, if you tried with 5.0.45, there is no need to try anything newer. 

But without exact (small) test case (in C++, sorry for a mistake) how do you think anybody will be able to repeat this your exact problem? Whatever code I will write based on your description, it may demonstrate this problem, some other problem (like a bug in my code) or no problems at all. So, please, provide test case containing enough information to understand how exactly your code works, explain what results you expected and why, and send the actual results you get.
[30 Nov 2007 14:21] Angus M
I'm afraid I can't cause the problem anymore. The exception that was thrown was due to some bugs that have long been fixed while I was working on the workaround.
   FWIW, even though the code was buggy, those bugs should not have been a fundamental part of the problem, since I had try-catch blocks everywhere, so any exception thrown should have been caught. Furthermore, the turning-point between the problem occurring and not occurring was when I replaced the mysql_thread_init() with mysql_init() and mysql_real_connect().