Skip to content

MDEV-39585/MDEV-39541 - mariadbd --bootstrap crashing in ~mem_pressure#5070

Open
grooverdan wants to merge 3 commits into
MariaDB:10.11from
grooverdan:MDEV-39541
Open

MDEV-39585/MDEV-39541 - mariadbd --bootstrap crashing in ~mem_pressure#5070
grooverdan wants to merge 3 commits into
MariaDB:10.11from
grooverdan:MDEV-39541

Conversation

@grooverdan
Copy link
Copy Markdown
Member

MDEV-39585 on the first commit corrects the server operation to call a shutdown of plugins under bootstrap.

Second commit was a @Thirunarayanan suggestion of enforcing a fast shutdown (=2 was suggested by failed badly).

Finally we add the mem_pressure such that it joins the thread before attempting to kill it off.

@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label May 13, 2026
@grooverdan grooverdan requested a review from Thirunarayanan May 13, 2026 06:09
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a crash during bootstrap (MDEV-39541) by refining the server shutdown sequence and InnoDB's memory pressure thread handling. Key changes include moving the signal thread termination to a common exit path in mysqld_main, replacing direct exits with a jump to a cleanup label, and ensuring the memory pressure thread is shut down even if InnoDB initialization is incomplete. Feedback suggests using exchange(nullptr) when retrieving the shutdown_user pointer to enhance thread safety and prevent potential double-free issues during the shutdown sequence.

Comment thread sql/mysqld.cc
Comment on lines +6128 to +6130
char *user= shutdown_user.load(std::memory_order_relaxed);
if (user)
my_free(user);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is safer to use exchange(nullptr) when retrieving the pointer from the atomic shutdown_user for freeing. This ensures that the atomic is cleared and prevents any potential double-free or dangling pointer issues if other parts of the shutdown sequence (e.g., in clean_up) were to access the same pointer.

    char *user= shutdown_user.exchange(nullptr, std::memory_order_relaxed);
    if (user)
      my_free(user);

mariadbd under --bootstrap failed to preform plugin deinitialization.

The sleep(2);exit is removed and replaced to a goto termination label
to perform the same shutdown procedure of the server after all the
connection closing.

To prevent a compile error about char *user being uninitialized
this sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN)) is moved to
its own block. The memory free did need to occur in the bootstrap mode
too to avoid memory leak errors.

wait_for_signal_thread_to_end(), was previously in close_connections()
however its required too for --bootstrap.
Now that mariadbd is doing a plugin shutdown, we
want the InnoDB termination to be quick.
Fill in the anomaly shutdown paths of InnoDB to include call to
buf_mem_pressure_shutdown now that MDEV-39585 provides some
proper calls shutdown InnoDB and other plugins during the shutdown
under --bootstrap.

Alternate: destructor attribute on buf_mem_pressure_shutdown would
acheive the same thing and given Linux compilers are capabile of
this. This is possible as mem_pressure is currently implemented
in Linux onny.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

1 participant