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

SIGSEGV in spider_free_mem from ha_spider::open on INSERT

Details

    Description

      During the investigation for MDEV-24769, I hit another crash bug possibly related to the Spider SE.

      How to reproduce:

      INSTALL PLUGIN spider SONAME 'ha_spider.so';
      SET @@session.spider_same_server_link = ON; 
       
      use test;
       
      GRANT ALL PRIVILEGES ON *.* TO 'spinne'@'127.0.0.1'  IDENTIFIED BY 'password';
       
      CREATE SERVER IF NOT EXISTS data1
      FOREIGN DATA WRAPPER mysql
      OPTIONS(
      HOST '127.0.0.1',
      DATABASE 'test',
      USER 'spinne',
      PORT 16000,
      PASSWORD 'password'
      );
       
      CREATE TABLE IF NOT EXISTS `spider_tab` (
        `col1`int,
        `col2`int,
        PRIMARY KEY (`col1`)
      ) ENGINE=SPIDER DEFAULT CHARSET=utf8 COMMENT='table "spider_data_tab"'
      PARTITION BY LIST COLUMNS(`col1`)
      (PARTITION `pt1` DEFAULT COMMENT = 'srv "data1"' ENGINE = SPIDER);
       
      CREATE TABLE IF NOT EXISTS `spider_data_tab` (
        `col1` int,
        `col2` int,
        PRIMARY KEY (`col1`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
       
      insert into `spider_data_tab` VALUES (1,999), (2,999);
       
      insert into spider_tab select col1+10, col2 from spider_tab;
      

      Error log:

      Version: '10.5.10-MariaDB-debug-log'  socket: '/home/vagrant/repo/mariadb-server/bld/mysql-test/var/tmp/mysqld.1.1.sock'  port: 16020  Source distribution
      210716  6:47:18 [ERROR] mysqld got signal 11 ;
      This could be because you hit a bug. It is also possible that this binary
      or one of the libraries it was linked against is corrupt, improperly built,
      or misconfigured. This error can also be caused by malfunctioning hardware.
       
      To report this bug, see https://mariadb.com/kb/en/reporting-bugs
       
      We will try our best to scrape up some info that will hopefully help
      diagnose the problem, but since we have already crashed,
      something is definitely wrong and this may fail.
       
      Server version: 10.5.10-MariaDB-debug-log
      key_buffer_size=1048576
      read_buffer_size=131072
      max_used_connections=1
      max_threads=153
      thread_count=22
      It is possible that mysqld could use up to
      key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 63751 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x7f8830000db8
      Attempting backtrace. You can use the following information to find out
      where mysqld died. If you see no messages after this, something went
      terribly wrong...
      stack_bottom = 0x7f885ee67d98 thread_stack 0x49000
      mysys/stacktrace.c:212(my_print_stacktrace)[0x55b006c91891]
      sql/signal_handler.cc:224(handle_fatal_signal)[0x55b0063668f2]
      ??:0(__restore_rt)[0x7f88c03c43c0]
      spider/spd_malloc.cc:185(spider_free_mem(st_spider_transaction*, void*, unsigned long))[0x7f88bf94db66]
      spider/ha_spider.cc:669(ha_spider::open(char const*, int, unsigned int))[0x7f88bf95df62]
      sql/handler.cc:2983(handler::ha_open(TABLE*, char const*, int, unsigned int, st_mem_root*, List<String>*))[0x55b0063708a6]
      sql/ha_partition.cc:8641(ha_partition::open_read_partitions(char*, unsigned long))[0x55b0066bb33c]
      sql/ha_partition.cc:3714(ha_partition::open(char const*, int, unsigned int))[0x55b0066ad1d2]
      sql/handler.cc:2983(handler::ha_open(TABLE*, char const*, int, unsigned int, st_mem_root*, List<String>*))[0x55b0063708a6]
      sql/table.cc:4218(open_table_from_share(THD*, TABLE_SHARE*, st_mysql_const_lex_string const*, unsigned int, unsigned int, unsigned int, TABLE*, bool, List<String>*))[0x55b0061476c3]
      sql/sql_base.cc:2001(open_table(THD*, TABLE_LIST*, Open_table_context*))[0x55b005f4f5b9]
      sql/sql_base.cc:3801(open_and_process_table(THD*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*))[0x55b005f534c4]
      sql/sql_base.cc:4275(open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*))[0x55b005f5478c]
      sql/sql_base.cc:5211(open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*))[0x55b005f56731]
      sql/sql_base.h:507(open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int))[0x55b005f0c049]
      sql/sql_parse.cc:4712(mysql_execute_command(THD*))[0x55b0060003e8]
      sql/sql_parse.cc:8099(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55b00600b78a]
      sql/sql_parse.cc:1894(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55b005ff7701]
      sql/sql_parse.cc:1370(do_command(THD*))[0x55b005ff5ef3]
      sql/sql_connect.cc:1410(do_handle_one_connection(CONNECT*, bool))[0x55b0061a5aff]
      sql/sql_connect.cc:1314(handle_one_connection)[0x55b0061a5862]
      perfschema/pfs.cc:2203(pfs_spawn_thread)[0x55b0066c93bb]
      ??:0(start_thread)[0x7f88c03b8609]
      ??:0(clone)[0x7f88bff8b293]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x7f8830013f20): insert into spider_tab select col1+10, col2 from spider_tab
       
      Connection ID (thread ID): 24
      Status: NOT_KILLED
       
      Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
      

      Attachments

        Issue Links

          Activity

            A refined MTR test case:

            --echo #
            --echo # MDEV-26158 SIGSEGV in spider_free_mem from ha_spider::open on INSERT
            --echo #
             
            --disable_query_log
            --disable_result_log
            --source ../../t/test_init.inc
            --enable_result_log
            --enable_query_log
             
            --connection master_1
            CREATE DATABASE auto_test_local;
            USE auto_test_local;
             
            eval CREATE TABLE t (
                c INT
            ) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"'
            PARTITION BY LIST COLUMNS(`c`) (
                PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"'
            );
             
            --error 1429
            INSERT INTO t SELECT * FROM t;
             
            DROP DATABASE auto_test_local;
             
            --disable_query_log
            --disable_result_log
            --source ../../t/test_deinit.inc
            --enable_result_log
            --enable_query_log
            

            nayuta-yanagisawa Nayuta Yanagisawa (Inactive) added a comment - A refined MTR test case: --echo # --echo # MDEV-26158 SIGSEGV in spider_free_mem from ha_spider::open on INSERT --echo #   --disable_query_log --disable_result_log --source ../../t/test_init.inc --enable_result_log --enable_query_log   --connection master_1 CREATE DATABASE auto_test_local; USE auto_test_local;   eval CREATE TABLE t ( c INT ) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT= 'table "tbl_a"' PARTITION BY LIST COLUMNS(`c`) ( PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"' );   --error 1429 INSERT INTO t SELECT * FROM t;   DROP DATABASE auto_test_local;   --disable_query_log --disable_result_log --source ../../t/test_deinit.inc --enable_result_log --enable_query_log

            In the above MTR test case, spider_get_share() fails due to non-existing remote database. Then, Spider jums to the error_get_share label, calls the spider_free() macro, and then SIGSEGV.

            nayuta-yanagisawa Nayuta Yanagisawa (Inactive) added a comment - In the above MTR test case, spider_get_share() fails due to non-existing remote database. Then, Spider jums to the error_get_share label, calls the spider_free() macro, and then SIGSEGV.

            In the below code fragment, this == pt_handler_share_handlers[0]. So, it nullifies wide_handler and then tries to free it.

            int ha_spider::open(
            ...
            error_get_share:
              if (wide_handler_alloc)
              {
            #ifdef WITH_PARTITION_STORAGE_ENGINE
                if (pt_handler_share_handlers)
                {
                  pt_handler_share_handlers[0]->wide_handler = NULL;
                }
            #endif
                spider_free(spider_current_trx, wide_handler, MYF(0));
                spider->wide_handler = NULL;
                owner->wide_handler = NULL;
                owner->wide_handler_owner = FALSE;
              }
              wide_handler = NULL;
            ...
            }
            

            nayuta-yanagisawa Nayuta Yanagisawa (Inactive) added a comment - - edited In the below code fragment, this == pt_handler_share_handlers [0] . So, it nullifies wide_handler and then tries to free it. int ha_spider::open( ... error_get_share: if (wide_handler_alloc) { #ifdef WITH_PARTITION_STORAGE_ENGINE if (pt_handler_share_handlers) { pt_handler_share_handlers[0]->wide_handler = NULL; } #endif spider_free(spider_current_trx, wide_handler, MYF(0)); spider->wide_handler = NULL; owner->wide_handler = NULL; owner->wide_handler_owner = FALSE; } wide_handler = NULL; ... }
            nayuta-yanagisawa Nayuta Yanagisawa (Inactive) added a comment - holyfoot Please review: https://github.com/MariaDB/server/commit/93a8c3304877d6355faad033301afaee0a3477dd

            Patch is ok to push.

            holyfoot Alexey Botchkov added a comment - Patch is ok to push.

            People

              nayuta-yanagisawa Nayuta Yanagisawa (Inactive)
              nayuta-yanagisawa Nayuta Yanagisawa (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.