Bug #111793 mysqldump memory leaks
Submitted: 18 Jul 2023 15:06 Modified: 6 Dec 2024 0:52
Reporter: Pedro Ferreira Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S2 (Serious)
Version:8.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: mysqldump

[18 Jul 2023 15:06] Pedro Ferreira
Description:
On a brand new database, set the sort buffer size very small:

SET GLOBAL SORT_BUFFER_SIZE = 32768;

Then run:

mysqldump -u ... --force --order-by-primary --all-databases

The leak sanitizer will report many leaks like this one:

Indirect leak of 816 byte(s) in 1 object(s) allocated from:
    #0 0x7f756ccb4867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x555aba49b910 in redirecting_allocator mysys/my_malloc.cc:279
    #2 0x555aba49c271 in my_raw_malloc<redirecting_allocator> mysys/my_malloc.cc:322
    #3 0x555aba49c3dc in my_internal_malloc<redirecting_allocator> mysys/my_malloc.cc:372
    #4 0x555aba49c65f in my_malloc(unsigned int, unsigned long, int) mysys/my_malloc.cc:386
    #5 0x555aba485644 in MEM_ROOT::AllocBlock(unsigned long, unsigned long) mysys/my_alloc.cc:89
    #6 0x555aba485b04 in MEM_ROOT::AllocSlow(unsigned long) mysys/my_alloc.cc:122
    #7 0x555aba1e4de7 in MEM_ROOT::Alloc(unsigned long) include/my_alloc.h:164
    #8 0x555aba234342 in cli_read_metadata_ex sql-common/client.cc:2658
    #9 0x555aba250829 in cli_read_metadata sql-common/client.cc:2722
    #10 0x555aba250bd1 in read_com_query_metadata sql-common/client.cc:2765
    #11 0x555aba252950 in cli_read_query_result sql-common/client.cc:7716
    #12 0x555aba27b4e3 in mysql_real_query sql-common/client.cc:8064
    #13 0x555aba1f6813 in mysql_query libmysql/libmysql.cc:663
    #14 0x555aba1c73d4 in mysql_query_with_error_report client/mysqldump.cc:1208
    #15 0x555aba1dc2b0 in dump_table client/mysqldump.cc:3862
    #16 0x555aba1df086 in dump_all_tables_in_db client/mysqldump.cc:4682
    #17 0x555aba1dfb46 in dump_all_databases client/mysqldump.cc:4457
    #18 0x555aba1e2978 in main client/mysqldump.cc:6029
    #19 0x7f756b629d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

How to repeat:
Run the query, then mysqldump above.
[19 Jul 2023 12:17] MySQL Verification Team
Hi Mr. Ferreira,

Thank you for your bug report.

However, we need the additional information in order to be able to process it further.

Minimum value of that system variable is not recommended. Do you have the same problems with default value ???

Next, how many schemas and tables do you have and is there anything particular in them. Can you upload the table that makes this problem ???

Next, you have set the category to Server, while it is evidently not a bug in the server.

Next, which memory analyser tools have you used ??? One or several of them. We need that info in order rto try to repeat it.

We are waiting on your feedback.
[19 Jul 2023 14:04] Pedro Ferreira
Hello,

I am using a testing tool and sometimes I need to test low memory situations, that's why I set the sort buffer size too low.

The database was empty, I just initialized it, set the buffer size, then run the dump.

I built the server with ASAN, but I forgot to mention it, my apologies:

-DWITH_DEBUG=1 -DWITH_ASAN=ON -DWITH_UBSAN=ON
[19 Jul 2023 14:15] MySQL Verification Team
Hi Mr. Ferreira,

We have managed to repeat the behaviour.

We have also got the error message on both mysqldump and server side:

Error 1038: Out of sort memory, consider increasing server sort buffer size when dumping table `help_topic` at row: 0

This is now a verified bug.
[6 Dec 2024 0:52] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Server 9.3.0 release, and here's the proposed changelog entry from the documentation team:

Fixed a memory leak in the mysqldump client.

Thank you for the bug report.
[6 Dec 2024 10:57] MySQL Verification Team
Thank you, Philip.