Bug #12898 | query causes core dump in libmysql after mysql server restart | ||
---|---|---|---|
Submitted: | 31 Aug 2005 6:48 | Modified: | 9 Apr 2008 9:33 |
Reporter: | Matt Provost | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1.10a | OS: | Linux (Fedora Core 2) |
Assigned to: | CPU Architecture: | Any |
[31 Aug 2005 6:48]
Matt Provost
[31 Aug 2005 9:08]
Andrey Hristov
Hi, as you have a reproducing case with everything set up, could you build a debug version of libmysqlclient_r and then post again the backtrace (which should include line numbers). You can build from source by using compile-pentium-debug-no-bdb script from the BUILD directory and the install the client libraries from libmysql/. Thank you in advance!
[31 Aug 2005 15:24]
Matt Provost
The user rebuilt a debug version and now gets this: [08/31 10:05:58 Queue ready, broadcasting thread go condition.] Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 127, 'net.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 34, 'viosocket.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 34, 'viosocket.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' <at this point, output stops, and program hangs> There's no core dump anymore. Did they build it correctly, or is this showing the error?
[31 Aug 2005 15:29]
Brandon Ewing
While I don't have much experience with the debug version of MySQL, I believe I followed the instructions correctly: I downloaded the mysql source, and ran BUILD/compile-pentium-debug-no-bdb, then copied libmysql_r/.libs/libmysqlclient_r.* to the correct directories (.so's to /usr/lib, .la and .a to /usr/lib/mysql). I then rebuilt rtg, started the poller, and restarted the MySQL server. It created the following output to stdout (and this is where I don't know if it's normal, because it never actually crashed and generated a core): [No Resp = 0] [SNMP Errs = 0] [Slow = 0] [PollTime = 44.617s] Next Poll: 10...9...8...7...6...5...4...3...2...1... [08/31 10:05:58 Queue ready, broadcasting thread go condition.] Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 127, 'net.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 34, 'viosocket.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Error: Freeing unallocated data at line 34, 'viosocket.c' Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' <at this point, output stops, and program hangs> Like I said, I'm not sure this is what you're asking for, as it never generates a core to backtrace. :/ This is on MySQL 4.0.25, CentOS-4
[1 Sep 2005 17:05]
Hartmut Holzgraefe
to me this looks like either an invalid pointer passed to mysql_close() or mysql_close() being called twice for the same MYSQL *?
[2 Sep 2005 5:45]
Hartmut Holzgraefe
well, looking at the backtrace again i see #10 0x00ae9b40 in mysql_close () from /usr/lib/libmysqlclient_r.so.12 #11 0x00ae9c94 in mysql_close () from /usr/lib/libmysqlclient_r.so.12 mysql_close() only calls itself when freeing master or slave entries that have been set with the mysql_set_master() and mysql_add_slave() calls. as these are not used at all here this is another indication of memory corruption maybe several threads are trying to perform the mysql_close(); exit(); sequence in rtgpoll.c at the same time? could wrapping it up with a mutex help? anyway, looks like an application problem and not a mysql bug to me ...
[2 Sep 2005 5:46]
Matt Provost
Yes I think it might be closing the connection twice, but it's happening in the driver not in our code. We just call mysql_real_query, but if it detects that the server restarted then it looks like it closes the connection (twice) and tries to reconnect. We aren't calling mysql_close anywhere in this code path. The only place we call mysql_close is from a function pushed onto the pthread_cleanup stack for when the program exits. Is there something in the driver that is closing it twice when it detects that it's been disconnected from the server?
[2 Sep 2005 7:13]
Matt Provost
Each thread has it's own connection that it stores in thread-local storage, so they shouldn't be using the same MYSQL *. Looking at the debug output: Error: Freeing unallocated data at line 2281, 'libmysql.c' Error: Freeing unallocated data at line 2282, 'libmysql.c' Error: Freeing unallocated data at line 2283, 'libmysql.c' Error: Freeing unallocated data at line 2284, 'libmysql.c' Those lines are: my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); in mysql_close. Those pointers are freed on line 2299 also in mysql_close: mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; The other debug line that is interesting is: Error: Freeing unallocated data at line 34, 'viosocket.c' That is: my_free((gptr) vio,MYF(0)); in vio_delete, which is called by end_server which is called by mysql_close. So to me it looks like it's trying to close the same MYSQL twice, but I don't see how it's failing either of the two cases for master or slave. If it's the in RTG code I'd love to fix it but I don't see how what we're doing could affect this.
[24 Sep 2005 17:50]
Valeriy Kravchuk
Please, look at the http://bugs.mysql.com/bug.php?id=13457. It is a bug report about similar problem with calling mysql_close after server shutdown. Note the last comment from Miguel - compare the sequence of calls in your code and in mysql.cc: mysql_close is called in mysql_end (normal exit) and sql_real_connect (upon reconnection, if needed) functions ONLY! You application should do the same. Inform, please, about the results of comparison and change you application if needed.
[26 Sep 2005 1:46]
Matt Provost
We're not calling mysql_close in our code. It looks like it's being called from within the mysql driver in mysql_reconnect when it discovers that the connection has gone away and tries to reconnect. This is the entire function: int __db_insert(char *table, int iid, unsigned long long insert_val, double insert_rate) { MYSQL mysql = getmysql(); char *query; char *table_esc; int result; table_esc = escape_string(table_esc, table); asprintf(&query, "INSERT INTO `%s` (id,dtime,counter,rate) VALUES (%i,NOW(),%llu,%.6f)", table_esc, iid, insert_val, insert_rate); free(table_esc); debug(HIGH, "Query = \"%s\"\n", query); /* now execute the query */ result = mysql_real_query(&mysql, query, strlen(query)); free(query); if (result == 0) { return TRUE; } else { debug(LOW, "MySQL error: %s\n", mysql_error(&mysql)); return FALSE; } } As you can see, we only call mysql_real_query and that's where it crashes, but I don't see how we can do anything to affect the mysql_close that is happening inside mysql_real_query.
[12 Oct 2005 3:00]
MySQL Verification Team
I was unable for to repeat the behavior reported testing simples application with my own. It is possible for you to create a standalone C test case which can shows the issue ? Thanks in advance.
[13 Nov 2005 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".
[9 Apr 2008 9:33]
Susanne Ebrecht
I closed this bug. There aren't any corruption anymore by using newer versions of MySQL and operating system.