Skip to content

Conversation

garenchan
Copy link

@garenchan garenchan commented Nov 2, 2021

MySQL version:

mysql Ver 14.14 Distrib 5.7.32, for Linux (x86_64) using EditLine wrapper

Background:

As described in the documentation, we set host_cache_size to 0 instead of --skip-host-cache.

Using the --skip-host-cache option is similar to setting the host_cache_size system variable to 0, 
but host_cache_size is more flexible because it can also be used to resize, enable, and disable the host cache at 
runtime, not just at server startup. 

But after a long run, we found a serious memory leak. Here is the valgrind log:

==12835== 1,354,080 bytes in 4,030 blocks are definitely lost in loss record 2,243 of 2,281
==12835== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12835== by 0xD774F9: add_hostname_impl (hostname.cc:209)
==12835== by 0xD774F9: add_hostname(char const*, char const*, bool, Host_errors*) [clone .part.7] [clone .constprop.9] (hostname.cc:290)
==12835== by 0xD786D2: add_hostname (hash_filo.h:133)
==12835== by 0xD786D2: ip_to_hostname(sockaddr_storage*, char const*, char**, unsigned int*) (hostname.cc:1017)
==12835== by 0xBAB1A4: check_connection(THD*, bool) [clone .constprop.12] (sql_connect.cc:1234)
==12835== by 0xBACE78: login_connection (sql_connect.cc:1368)
==12835== by 0xBACE78: thd_prepare_connection(THD*, bool) (sql_connect.cc:1531)
==12835== by 0xCB71FC: handle_connection (connection_handler_per_thread.cc:319)
==12835== by 0xEC89A3: pfs_spawn_thread (pfs.cc:2198)
==12835== by 0x52476B9: start_thread (pthread_create.c:333)
==12835== by 0x713B41C: clone (clone.S:109)

==12835== LEAK SUMMARY:
==12835== definitely lost: 1,354,080 bytes in 4,030 blocks
==12835== indirectly lost: 0 bytes in 0 blocks
==12835== possibly lost: 124,136,716 bytes in 42,518 blocks
==12835== still reachable: 113,162,426 bytes in 8,313 blocks
==12835== of which reachable via heuristic:
==12835== newarray : 1,104 bytes in 2 blocks
==12835== suppressed: 0 bytes in 0 blocks

Reason:

While host_cache_size is 0, hostname_cache->add(entry) will always fail, but we did not free memory of entry.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@garenchan
Copy link
Author

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=105442 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants