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

Semisync ack-receiver THD can be destroyed after LOCK_plugin is destroyed during a pre-close startup abort (order regression from the MDEV-32551 reorder)

    XMLWordPrintable

Details

    • Can result in hang or crash

    Description

      With `--rpl-semi-sync-master-enabled=ON`, `clean_up()` stops the semisync master and then shuts the
      plugin subsystem down:

      • `sql/mysqld.cc:5818` — semi-sync master initialization during startup.
      • `sql/mysqld.cc:5936` — the pre-close abort path (also `sql/mysqld.cc:2535`) that reaches
        `clean_up()` before the normal `close_connections()` shutdown sequence.
      • `sql/mysqld.cc:2181` — `semi_sync_master_deinit()`.
      • `sql/mysqld.cc:2183` — `plugin_shutdown()` immediately afterwards.
      • `sql/mysqld.cc:1969` — `close_connections()`, which is what normally stops the ack receiver
        earlier and masks the race.

      The ack-receiver thread's `run()` destroys its THD at the end, and the THD destructor takes
      `LOCK_plugin` (`sql/sql_plugin.cc:3464`, `sql/sql_class.cc:1841/1937`). After the MDEV-32551 rework,
      `stop()` returns as soon as `m_status == ST_DOWN` while `delete thd` is still pending
      (`sql/semisync_master_ack_receiver.cc:383-390`, `sql/semisync_master.cc:1562-1566`). `clean_up()` then
      calls `plugin_shutdown()`, which locks and destroys `LOCK_plugin` and releases the plugin hash
      (`sql/sql_plugin.cc:2239-2240`) while the ack THD may still be running its destructor — the THD can
      lock a destroyed mutex and access freed plugin state.

        1. Expected result

      `stop()` must not report `ST_DOWN` before the ack THD has actually been destroyed (or
      `semi_sync_master_deinit()` must explicitly join the ack thread), so that `plugin_shutdown()` cannot
      destroy `LOCK_plugin` while a THD destructor still needs it.

      Attachments

        Activity

          People

            Deepthi ES Deepthi Eranti Sreenivas
            csfuzz csfuzz
            Jimmy Hú Jimmy Hú
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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