Bug #92041 TSAN: Data race in Event_queue::lock_data
Submitted: 16 Aug 2018 10:50 Modified: 29 Aug 2018 18:15
Reporter: Jon Olav Hauglid Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:8.0.14 OS:Any
Assigned to: CPU Architecture:Any

[16 Aug 2018 10:50] Jon Olav Hauglid
Description:
Running any MTR test that uses Events with Thread Sanitizer, gives this data race:
WARNING: ThreadSanitizer: data race (pid=10571)
  Write of size 1 at 0x7b3000001af9 by thread T43:
    #0 Event_queue::lock_data(char const*, unsigned int) /export2/repo/mysql/sql/event_queue.cc:670 (mysqld+0x2d153c9)
    #1 Event_queue::drop_schema_events(MYSQL_LEX_STRING) /export2/repo/mysql/sql/event_queue.cc:336 (mysqld+0x2d1626e)
    #2 Events::drop_schema_events(THD*, dd::Schema const&) /export2/repo/mysql/sql/events.cc:740 (mysqld+0x28cc844)
    #3 mysql_rm_db(THD*, MYSQL_LEX_CSTRING const&, bool) /export2/repo/mysql/sql/sql_db.cc:630 (mysqld+0x26b2239)
    #4 mysql_execute_command(THD*, bool) /export2/repo/mysql/sql/sql_parse.cc:3495 (mysqld+0x2724436)
    #5 mysql_parse(THD*, Parser_state*, bool) /export2/repo/mysql/sql/sql_parse.cc:5033 (mysqld+0x2720261)
    #6 dispatch_command(THD*, COM_DATA const*, enum_server_command) /export2/repo/mysql/sql/sql_parse.cc:1677 (mysqld+0x271d895)
    #7 do_command(THD*) /export2/repo/mysql/sql/sql_parse.cc:1233 (mysqld+0x271f3de)
    #8 handle_connection(void*) /export2/repo/mysql/sql/conn_handler/connection_handler_per_thread.cc:303 (mysqld+0x28bcc63)
    #9 pfs_spawn_thread(void*) /export2/repo/mysql/storage/perfschema/pfs.cc:2836 (mysqld+0x4281dc1)

  Previous write of size 1 at 0x7b3000001af9 by thread T38 (mutexes: write M525367666731525320):
    #0 Event_queue::lock_data(char const*, unsigned int) /export2/repo/mysql/sql/event_queue.cc:674 (mysqld+0x2d15408)
    #1 Event_queue::get_top_for_execution_if_time(THD*, Event_queue_element_for_exec**) /export2/repo/mysql/sql/event_queue.cc:546 (mysqld+0x2d168bd)
    #2 Event_scheduler::run(THD*) /export2/repo/mysql/sql/event_scheduler.cc:548 (mysqld+0x2d1b9b7)
    #3 event_scheduler_thread(void*) /export2/repo/mysql/sql/event_scheduler.cc:268 (mysqld+0x2d1b746)
    #4 pfs_spawn_thread(void*) /export2/repo/mysql/storage/perfschema/pfs.cc:2836 (mysqld+0x4281dc1)

This race can have consequences for the "Event queue status" printout during crash reporting.

How to repeat:
See above.

Suggested fix:
Use atomics.
[29 Aug 2018 18:15] Paul Dubois
Posted by developer:
 
Fixed in 8.0.14.

Data races discovered by Thread Sanitizer in Event_queue::lock_data
and the SAFE_MUTEX implementation were fixed.