Bug #41810 Writing from Multiple threads to different tables crashes the application
Submitted: 31 Dec 2008 18:55 Modified: 15 Feb 2009 13:07
Reporter: Mikhail Veygman Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0.51a OS:Linux (RHEL 5/Ubuntu 8.04)
Assigned to: CPU Architecture:Any
Tags: Multi thread crash

[31 Dec 2008 18:55] Mikhail Veygman
Description:
When attempting to access multiple tables from different threads using prepared queries creates error of SERVER_GONE or similar.  Application is compiled with libmysqlclient_r library.

How to repeat:
create database test1;
create table test_read
(
   test_value         int
);

insert into test1.test_table values(0);
insert into test1.test_table values(1);
insert into test1.test_table values(2);
insert into test1.test_table values(3);

create database test2;
create table test_write
(
   test_value          int
)

insert into test2.test_write values(0);

I don't have the C Example Code to repeat it, but the basic idea is:

Create prepared queries for:

select test_value from test1.test_read;

and

update test2.test_write set test_value = ?

In one thread run query 1 in the other run query 2.  At some point during the run the query will return SERVER_GONE error.
[1 Jan 2009 15:02] Valeriy Kravchuk
Thank you for a problem report. Please, try to repeat with a newer version, 5.0.67 at least, and inform about the results.
[2 Jan 2009 15:47] Mikhail Veygman
When running on 5.0.67 the server reports Error CR_COMMANDS_OUT_OF_SYNC.  Does this imply that the multiple threads are not being internally arbitrated?
[2 Jan 2009 18:07] Mikhail Veygman
Tested the same with 5.1.30.  Error reporting of SERVER_LOST or SERVER_GONE during the execution or UNKNOWN_ERROR during the read.
[3 Jan 2009 0:04] Mikhail Veygman
I think I found a problem that may be the cause.

I the Connection object is created in one thread an used in a different thread while another connection object is used in the orignal thread the conflict may be producing such results.  This would be a problem if the same connection will have to be used from within multiple threads.
[3 Jan 2009 13:10] MySQL Verification Team
Could you please provide a C test case, it is hard to know if really is a bug you are reporting just describing the use and the error messages, please read:

http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html

"Two threads can't send a query to the MySQL server at the same time on the same connection. In particular, you have to ensure that between calls to mysql_query() and mysql_store_result(), no other thread is using the same connection."

Thanks in advance.
[4 Jan 2009 16:35] Mikhail Veygman
I will put together the example, but the documentation answers the issue I had.
[4 Jan 2009 16:37] Mikhail Veygman
Actually not quite.  The thread executions were performed on 2 different connections created within the same thread but from different threads.  If the connections are created in different threads I have not observed the issue... yet.
[15 Jan 2009 13:07] MySQL Verification Team
Changing to need feedback waiting for the C test case.
[16 Feb 2009 0: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".