Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19493

Server crashes in lock_tables_check or get_lock_data upon multi-table update

    Details

      Description

      Run with --repeat=N. It usually fails for me within a few attempts, but it can vary a lot.

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (pk int, a int, b char(1), primary key (pk), key (b)) ENGINE=InnoDB;
      CREATE TABLE t2 (pk int, c char(1), d int, primary key (pk)) ENGINE=InnoDB;
       
      --connect (con1,localhost,root,,test)
      FLUSH TABLES;
      SELECT * FROM t2, t1;
      SET FOREIGN_KEY_CHECKS= OFF;
      ALTER TABLE t2 ADD FOREIGN KEY (c) REFERENCES t1 (b), ALGORITHM=INPLACE;
      SET FOREIGN_KEY_CHECKS= ON;
       
      --connection default
      --send
        FLUSH TABLES;
       
      --connection con1
      UPDATE t1 ta, t1 tb SET ta.a = 1;
      --disconnect con1
       
      # Cleanup
      --connection default
      --reap
      DROP TABLE t2, t1;
      

      10.2 409e210e

      #3  <signal handler called>
      #4  0x000055695b39ca40 in lock_tables_check (thd=0x7f29dc000b00, tables=0x7f29dc012788, count=2, flags=0) at /data/src/10.2/sql/lock.cc:125
      #5  0x000055695b39ce81 in mysql_lock_tables (thd=0x7f29dc000b00, tables=0x7f29dc012788, count=2, flags=0) at /data/src/10.2/sql/lock.cc:294
      #6  0x000055695afa127f in lock_tables (thd=0x7f29dc000b00, tables=0x7f29dc011198, count=2, flags=0) at /data/src/10.2/sql/sql_base.cc:5029
      #7  0x000055695b0fe3ad in mysql_multi_update_prepare (thd=0x7f29dc000b00) at /data/src/10.2/sql/sql_update.cc:1550
      #8  0x000055695b00f802 in mysql_execute_command (thd=0x7f29dc000b00) at /data/src/10.2/sql/sql_parse.cc:4320
      #9  0x000055695b01b4e2 in mysql_parse (thd=0x7f29dc000b00, rawbuf=0x7f29dc011098 "UPDATE t1 ta, t1 tb SET ta.a = 1", length=32, parser_state=0x7f2a2c37c200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:8020
      #10 0x000055695b008d36 in dispatch_command (command=COM_QUERY, thd=0x7f29dc000b00, packet=0x7f29dc0088b1 "UPDATE t1 ta, t1 tb SET ta.a = 1", packet_length=32, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1833
      #11 0x000055695b00768a in do_command (thd=0x7f29dc000b00) at /data/src/10.2/sql/sql_parse.cc:1386
      #12 0x000055695b15a35c in do_handle_one_connection (connect=0x55695e2b3e90) at /data/src/10.2/sql/sql_connect.cc:1335
      #13 0x000055695b15a0dc in handle_one_connection (arg=0x55695e2b3e90) at /data/src/10.2/sql/sql_connect.cc:1241
      #14 0x000055695b98569c in pfs_spawn_thread (arg=0x55695e2d74e0) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #15 0x00007f2a338ef4a4 in start_thread (arg=0x7f2a2c37d700) at pthread_create.c:456
      #16 0x00007f2a31e37d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      10.2 non-debug 409e210e

      #3  <signal handler called>
      #4  0x000055a3932e7a81 in get_lock_data (thd=thd@entry=0x7faca80009a8, table_ptr=table_ptr@entry=0x7faca8010700, count=count@entry=2, flags=flags@entry=3) at /data/src/10.2/sql/lock.cc:742
      #5  0x000055a3932e7e87 in mysql_lock_tables (thd=thd@entry=0x7faca80009a8, tables=0x7faca8010700, count=<optimized out>, flags=0) at /data/src/10.2/sql/lock.cc:300
      #6  0x000055a393058ca8 in lock_tables (thd=thd@entry=0x7faca80009a8, tables=0x7faca800f110, count=<optimized out>, flags=flags@entry=0) at /data/src/10.2/sql/sql_base.cc:5029
      #7  0x000055a39312e477 in mysql_multi_update_prepare (thd=thd@entry=0x7faca80009a8) at /data/src/10.2/sql/sql_update.cc:1550
      #8  0x000055a39309af16 in mysql_execute_command (thd=thd@entry=0x7faca80009a8) at /data/src/10.2/sql/sql_parse.cc:4320
      #9  0x000055a3930a0d9d in mysql_parse (thd=0x7faca80009a8, rawbuf=<optimized out>, length=32, parser_state=0x7facf5cf5240, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /data/src/10.2/sql/sql_parse.cc:8020
      #10 0x000055a3930a3c8c in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7faca80009a8, packet=packet@entry=0x7faca8006cf9 "UPDATE t1 ta, t1 tb SET ta.a = 1", packet_length=packet_length@entry=32, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.2/sql/sql_parse.cc:1833
      #11 0x000055a3930a4587 in do_command (thd=0x7faca80009a8) at /data/src/10.2/sql/sql_parse.cc:1386
      #12 0x000055a393161fb4 in do_handle_one_connection (connect=connect@entry=0x55a395ab5698) at /data/src/10.2/sql/sql_connect.cc:1335
      #13 0x000055a393162124 in handle_one_connection (arg=arg@entry=0x55a395ab5698) at /data/src/10.2/sql/sql_connect.cc:1241
      #14 0x000055a3936aeb34 in pfs_spawn_thread (arg=0x55a395a4e8a8) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #15 0x00007facfd2384a4 in start_thread (arg=0x7facf5cf6700) at pthread_create.c:456
      #16 0x00007facfb780d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      ASAN fails more reluctantly, I guess due to a different dynamics. Use bigger values of N in repeat=N.

      10.2 ASAN 409e210e

      ==22334==ERROR: AddressSanitizer: heap-use-after-free on address 0x61f000093b48 at pc 0x55a7e747db91 bp 0x7f7ee85ac720 sp 0x7f7ee85ac718
      READ of size 8 at 0x61f000093b48 thread T28
          #0 0x55a7e747db90 in multi_update_check_table_access /data/src/10.2/sql/sql_update.cc:1332
          #1 0x55a7e747ecc5 in mysql_multi_update_prepare(THD*) /data/src/10.2/sql/sql_update.cc:1527
          #2 0x55a7e723396a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:4320
          #3 0x55a7e724b773 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8020
          #4 0x55a7e72264b4 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1833
          #5 0x55a7e72234b3 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1386
          #6 0x55a7e755a308 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #7 0x55a7e7559ced in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #8 0x55a7e87a5fa2 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #9 0x7f7f001774a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
          #10 0x7f7efe6bfd0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
       
      0x61f000093b48 is located 2760 bytes inside of 3044-byte region [0x61f000093080,0x61f000093c64)
      freed by thread T28 here:
          #0 0x7f7f0044ea10 in free (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1a10)
          #1 0x55a7e88a85a6 in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x55a7e88a7c20 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x55a7e88788f4 in my_free /data/src/10.2/mysys/my_malloc.c:218
          #4 0x55a7e76b7f9b in intern_close_table /data/src/10.2/sql/table_cache.cc:224
          #5 0x55a7e76b81c6 in tc_remove_table /data/src/10.2/sql/table_cache.cc:260
          #6 0x55a7e76b9039 in tc_release_table(TABLE*) /data/src/10.2/sql/table_cache.cc:461
          #7 0x55a7e711bde5 in close_thread_table(THD*, TABLE**) /data/src/10.2/sql/sql_base.cc:911
          #8 0x55a7e711b6dc in close_thread_tables(THD*) /data/src/10.2/sql/sql_base.cc:859
          #9 0x55a7e712f2a8 in close_tables_for_reopen(THD*, TABLE_LIST**, MDL_savepoint const&) /data/src/10.2/sql/sql_base.cc:5218
          #10 0x55a7e71291c0 in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, Sroutine_hash_entry**, unsigned int, Prelocking_strategy*) /data/src/10.2/sql/sql_base.cc:4075
          #11 0x55a7e747ec51 in mysql_multi_update_prepare(THD*) /data/src/10.2/sql/sql_update.cc:1514
          #12 0x55a7e723396a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:4320
          #13 0x55a7e724b773 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8020
          #14 0x55a7e72264b4 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1833
          #15 0x55a7e72234b3 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1386
          #16 0x55a7e755a308 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #17 0x55a7e7559ced in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #18 0x55a7e87a5fa2 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #19 0x7f7f001774a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      previously allocated by thread T28 here:
          #0 0x7f7f0044ed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
          #1 0x55a7e88a75f7 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x55a7e8878057 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x55a7e711fe4f in open_table(THD*, TABLE_LIST*, Open_table_context*) /data/src/10.2/sql/sql_base.cc:1925
          #4 0x55a7e7126b99 in open_and_process_table /data/src/10.2/sql/sql_base.cc:3558
          #5 0x55a7e712916b in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, Sroutine_hash_entry**, unsigned int, Prelocking_strategy*) /data/src/10.2/sql/sql_base.cc:4052
          #6 0x55a7e7117dca in open_tables /data/src/10.2/sql/sql_base.h:251
          #7 0x55a7e712ce12 in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /data/src/10.2/sql/sql_base.cc:4810
          #8 0x55a7e710e801 in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /data/src/10.2/sql/sql_base.h:517
          #9 0x55a7e72423c6 in execute_sqlcom_select /data/src/10.2/sql/sql_parse.cc:6407
          #10 0x55a7e722fcec in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3534
          #11 0x55a7e724b773 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8020
          #12 0x55a7e72264b4 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1833
          #13 0x55a7e72234b3 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1386
          #14 0x55a7e755a308 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #15 0x55a7e7559ced in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x55a7e87a5fa2 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #17 0x7f7f001774a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      Thread T28 created by T0 here:
          #0 0x7f7f003bdf59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
          #1 0x55a7e87a63de in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1912
          #2 0x55a7e702b332 in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1239
          #3 0x55a7e703f976 in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6506
          #4 0x55a7e704006d in create_new_thread /data/src/10.2/sql/mysqld.cc:6576
          #5 0x55a7e7041094 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6851
          #6 0x55a7e703eebe in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6125
          #7 0x55a7e7029cbf in main /data/src/10.2/sql/main.cc:25
          #8 0x7f7efe5f72e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/sql/sql_update.cc:1332 in multi_update_check_table_access
      Shadow bytes around the buggy address:
        0x0c3e8000a710: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3e8000a720: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3e8000a730: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3e8000a740: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3e8000a750: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c3e8000a760: fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd
        0x0c3e8000a770: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3e8000a780: fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa fa
        0x0c3e8000a790: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c3e8000a7a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c3e8000a7b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      Shadow byte legend (one shadow byte represents 8 application bytes):
        Addressable:           00
        Partially addressable: 01 02 03 04 05 06 07 
        Heap left redzone:       fa
        Heap right redzone:      fb
        Freed heap region:       fd
        Stack left redzone:      f1
        Stack mid redzone:       f2
        Stack right redzone:     f3
        Stack partial redzone:   f4
        Stack after return:      f5
        Stack use after scope:   f8
        Global redzone:          f9
        Global init order:       f6
        Poisoned by user:        f7
        Container overflow:      fc
        Array cookie:            ac
        Intra object redzone:    bb
        ASan internal:           fe
        Left alloca redzone:     ca
        Right alloca redzone:    cb
      ==22334==ABORTING
      

        Attachments

          Activity

            People

            • Assignee:
              serg Sergei Golubchik
              Reporter:
              elenst Elena Stepanova
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: