Bug #17373 setting several events in different sessions crashes the server
Submitted: 14 Feb 2006 11:52 Modified: 21 Feb 2006 2:24
Reporter: Giuseppe Maxia Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S1 (Critical)
Version:5.1.6/5.1.7 BK OS:Linux (Linux (RHE-AS3 and FC4))
Assigned to: Andrey Hristov CPU Architecture:Any

[14 Feb 2006 11:52] Giuseppe Maxia
Description:
Launching an event and closing the session will crash the server when you are
connected in a new session at execution time.
Basically, you start a new event, wait for its completion while in the same session. It works.
Then you create two new events, to be completed in one hour.
Finally, you drop the first event, and re-create it, to execute in a short while. During this interval, you disconnect and reconnect the client, just in time to be there when the event should start.
In one of my servers (FC4), it crashes the server completely, in another one (RHE-AS3) it hangs all processes, saying that the event scheduler is busy opening tables.

How to repeat:
1) start the 5.1.6 server with 
   $ cd mysql_basedir
   $ bin/mysqld_safe --basedir=`pwd` --event-scheduler=1  --user=$USER &

2) execute the following script:
# ------------- CUT
use test;
drop table if exists t1 ;
create table t1 (
    id int not null auto_increment primary key,
    descr varchar(50),
    TS timestamp
);
drop event if exists justonce;
create event justonce
    on schedule at now() + interval 5 second
    do
    insert into t1 set descr = 'from event justonce';
select 'waiting 6 seconds' as message;
select sleep(6);
connect;
drop event if exists willdrop;
create event willdrop
    on schedule at now() + interval 30 minute
    do
    drop table if exists t2;
drop event if exists willcreate;
create event willcreate
    on schedule at now() + interval 30 minute
    do
    create table t2 like t1;
drop event if exists justonce;
create event justonce
    on schedule at now() + interval 5 second
    do
    insert into t1 set descr = 'from event justonce';
select sleep(1);
connect;
select "now don't do anything for 5 seconds" as message;
# ------------- CUT
Here is the situation when one of my servers crashes with a error, the other one will simply hang.

Here is the error message:

 *** glibc detected *** /usr/local/mysql/bin/mysqld: double free or corruption (!prev): 0x0ab857c0 ***
======= Backtrace: =========
/lib/libc.so.6[0xb61424]
/lib/libc.so.6(__libc_free+0x77)[0xb6195f]
/opt/mysqlstar/5.1.6/bin/mysqld(__builtin_delete+0x24)[0x85d0324]
/opt/mysqlstar/5.1.6/bin/mysqld(_._11event_timed+0x44)[0x85f8494]
/opt/mysqlstar/5.1.6/bin/mysqld(event_executor_main+0x2c0)[0x82d696c]
/lib/libpthread.so.0[0xd46b80]
/lib/libc.so.6(__clone+0x5e)[0xbc8dee]
(a long memory map follows)
[14 Feb 2006 14:52] MySQL Verification Team
Thank you for the bug report.

miguel@hegel:~/dbs/5.1> libexec/mysqld --event-scheduler=1
060214 12:50:58  InnoDB: Started; log sequence number 0 43655
060214 12:50:58 [Note] libexec/mysqld: ready for connections.
Version: '5.1.7-beta-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
060214 12:50:58 [Note] Scheduler loaded 0 events
060214 12:50:58 [Note] Scheduler thread started
060214 12:51:49 [Note]     EVEX EXECUTING event test.justonce [EXPR:0]
060214 12:51:49 [Note]     EVEX EXECUTED event test.justonce  [EXPR:0]. RetCode=0
060214 12:51:55 [Note] Event found disabled, dropping.
safe_mutex: Trying to destroy unitialized mutex at event.h, line 132
mysqld got signal 6;
[14 Feb 2006 17:15] Andrey Hristov
This issue is being fixed by the patch for bug #16406.
[16 Feb 2006 15:25] Andrey Hristov
Fixed in 5.1.7. The bugfix was part of the fix for #16406
[21 Feb 2006 2:24] Paul DuBois
Noted in 5.1.7 changelog.

          Race conditions between event creation, dropping, and
          execution could result in a server crash or hang. (Bug #17373)