drogon icon indicating copy to clipboard operation
drogon copied to clipboard

Mysql Client seems to have a memory leak?

Open nqf opened this issue 4 years ago • 14 comments

==20653== Memcheck, a memory error detector
==20653== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20653== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==20653== Command: ./aws_mysql_test --host=127.0.01 --user=mybb --password=123456 --dbname=mybb --threads=16 --client_num=16 --iterations=2 --port=3307
==20653== Parent PID: 36368
==20653== 
==20653== Warning: client switching stacks?  SP change: 0x987cf38 --> 0x84c0980
==20653==          to suppress, use: --max-stackframe=20694456 or greater
==20653== Warning: client switching stacks?  SP change: 0x907bf38 --> 0x855ad50
==20653==          to suppress, use: --max-stackframe=11669992 or greater
==20653== Warning: client switching stacks?  SP change: 0xa07df38 --> 0x856d8f0
==20653==          to suppress, use: --max-stackframe=28378696 or greater
==20653==          further instances of this message will not be shown.
==20653== 
==20653== HEAP SUMMARY:
==20653==     in use at exit: 104,947 bytes in 383 blocks
==20653==   total heap usage: 13,017 allocs, 12,634 frees, 4,008,914 bytes allocated
==20653== 
==20653== 208 bytes in 1 blocks are definitely lost in loss record 295 of 313
==20653==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==20653==    by 0x4E95A36: ??? (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E95C09: ??? (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E9366E: my_init (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E5ABAB: mysql_server_init (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E61E96: mysql_init (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x5B7E3A: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D9E08: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D8D67: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D7739: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D5E34: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D4415: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653== 
==20653== 3,120 bytes in 15 blocks are definitely lost in loss record 310 of 313
==20653==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==20653==    by 0x4E95A36: ??? (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E5ABC4: mysql_server_init (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x4E61E96: mysql_init (in /usr/lib64/mysql/libmysqlclient.so.18.0.0)
==20653==    by 0x5B7E3A: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D9E08: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D8D67: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D7739: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D5E34: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D4415: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D2A52: std::shared_ptr<drogon::orm::MysqlConnection>::shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653==    by 0x4D06D8: std::shared_ptr<drogon::orm::MysqlConnection> std::allocate_shared<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection> const&, trantor::EventLoop*&, std::string&) (in /home/fantasy/next/aws-db-test/build/aws_mysql_test)
==20653== 
==20653== LEAK SUMMARY:
==20653==    definitely lost: 3,328 bytes in 16 blocks
==20653==    indirectly lost: 0 bytes in 0 blocks
==20653==      possibly lost: 0 bytes in 0 blocks
==20653==    still reachable: 101,619 bytes in 367 blocks
==20653==         suppressed: 0 bytes in 0 blocks
==20653== Reachable blocks (those to which a pointer was found) are not shown.
==20653== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==20653== 
==20653== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

nqf avatar May 12 '22 01:05 nqf

Drogon is having problems exiting correctly now. The lost memories should be because of that. We will work on it. Thanks very much for your report.

hwc0919 avatar May 12 '22 07:05 hwc0919

Should be ok after #1250. Could you test it on your machine?

hwc0919 avatar May 18 '22 09:05 hwc0919

@hwc0919 use drogon v1.8.0 still have a memory leak, maybe need call mysql_library_end(); in drogon

==13766== Memcheck, a memory error detector
==13766== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13766== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==13766== Command: ./test-db -f ../cfg/test-db.yaml -D
==13766== Parent PID: 40502
==13766== 
==13766== Warning: client switching stacks?  SP change: 0x7a47a08 --> 0x5fcd9d0
==13766==          to suppress, use: --max-stackframe=27762744 or greater
==13766== Warning: client switching stacks?  SP change: 0xea55a08 --> 0x609b050
==13766==          to suppress, use: --max-stackframe=144419256 or greater
==13766== Warning: client switching stacks?  SP change: 0x7a46a58 --> 0x5fcd510
==13766==          to suppress, use: --max-stackframe=27759944 or greater
==13766==          further instances of this message will not be shown.
==13766== 
==13766== HEAP SUMMARY:
==13766==     in use at exit: 81,328 bytes in 37 blocks
==13766==   total heap usage: 17,454 allocs, 17,417 frees, 2,722,873 bytes allocated
==13766== 
==13766== 24 bytes in 1 blocks are still reachable in loss record 1 of 6
==13766==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==13766==    by 0x966F84: my_malloc (my_malloc.c:41)
==13766==    by 0x95FC03: my_error_register (my_error.c:196)
==13766==    by 0x950F24: mysql_server_init (libmysql.c:134)
==13766==    by 0x947286: mysql_init (client.c:1736)
==13766==    by 0x518C17: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B44CE: std::shared_ptr<drogon::orm::MysqlConnection>::shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766== 
==13766== 152 bytes in 1 blocks are still reachable in loss record 2 of 6
==13766==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==13766==    by 0x966F84: my_malloc (my_malloc.c:41)
==13766==    by 0x96C26D: init_alloc_root (my_alloc.c:63)
==13766==    by 0x9ABE9D: mysql_client_plugin_init (client_plugin.c:254)
==13766==    by 0x950F2B: mysql_server_init (libmysql.c:135)
==13766==    by 0x947286: mysql_init (client.c:1736)
==13766==    by 0x518C17: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766== 
==13766== 208 bytes in 1 blocks are definitely lost in loss record 3 of 6
==13766==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==13766==    by 0x96D27E: my_thread_init (my_thr_init.c:340)
==13766==    by 0x96D456: my_thread_global_init (my_thr_init.c:208)
==13766==    by 0x9628DE: my_init (my_init.c:104)
==13766==    by 0x950EFB: mysql_server_init (libmysql.c:132)
==13766==    by 0x947286: mysql_init (client.c:1736)
==13766==    by 0x518C17: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766== 
==13766== 3,120 bytes in 15 blocks are definitely lost in loss record 4 of 6
==13766==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==13766==    by 0x96D27E: my_thread_init (my_thr_init.c:340)
==13766==    by 0x950F14: mysql_server_init (libmysql.c:183)
==13766==    by 0x947286: mysql_init (client.c:1736)
==13766==    by 0x518C17: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B44CE: std::shared_ptr<drogon::orm::MysqlConnection>::shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766==    by 0x4B1E4E: std::shared_ptr<drogon::orm::MysqlConnection> std::allocate_shared<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection> const&, trantor::EventLoop*&, std::string&) (in /home/fantasy/test-db/build/test-db)
==13766== 
==13766== 36,864 bytes in 9 blocks are still reachable in loss record 5 of 6
==13766==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==13766==    by 0x9C5495: my_once_alloc (my_once.c:58)
==13766==    by 0x964201: init_state_maps (charset.c:66)
==13766==    by 0x96503B: init_available_charsets (charset.c:455)
==13766==    by 0x4E47E6F: pthread_once (in /usr/lib64/libpthread-2.17.so)
==13766==    by 0x96590D: get_charset_by_csname (charset.c:647)
==13766==    by 0x947597: mysql_set_character_set_with_default_collation (client.c:2289)
==13766==    by 0x947597: mysql_init_character_set (client.c:2328)
==13766==    by 0x948496: mysql_real_connect (client.c:3465)
==13766==    by 0x94A6E3: mysql_real_connect_start_internal (mysql_async.c:411)
==13766==    by 0x96BF54: my_context_spawn (my_context.c:205)
==13766== 
==13766== 40,960 bytes in 10 blocks are still reachable in loss record 6 of 6
==13766==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==13766==    by 0x9C5495: my_once_alloc (my_once.c:58)
==13766==    by 0x9641E2: init_state_maps (charset.c:63)
==13766==    by 0x96503B: init_available_charsets (charset.c:455)
==13766==    by 0x4E47E6F: pthread_once (in /usr/lib64/libpthread-2.17.so)
==13766==    by 0x96590D: get_charset_by_csname (charset.c:647)
==13766==    by 0x947597: mysql_set_character_set_with_default_collation (client.c:2289)
==13766==    by 0x947597: mysql_init_character_set (client.c:2328)
==13766==    by 0x948496: mysql_real_connect (client.c:3465)
==13766==    by 0x94A6E3: mysql_real_connect_start_internal (mysql_async.c:411)
==13766==    by 0x96BF54: my_context_spawn (my_context.c:205)
==13766== 
==13766== LEAK SUMMARY:
==13766==    definitely lost: 3,328 bytes in 16 blocks
==13766==    indirectly lost: 0 bytes in 0 blocks
==13766==      possibly lost: 0 bytes in 0 blocks
==13766==    still reachable: 78,000 bytes in 21 blocks
==13766==         suppressed: 0 bytes in 0 blocks
==13766== 
==13766== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

nqf avatar Sep 19 '22 02:09 nqf

I called mysql_library_end in my application, but this error occurred Error in my_thread_global_end(): 16 threads didn't exit

nqf avatar Sep 19 '22 02:09 nqf

it seem that also need call mysql_thread_end

nqf avatar Sep 19 '22 02:09 nqf

@nqf Please check #1387 out, thanks.

an-tao avatar Sep 19 '22 04:09 an-tao

==11618== Memcheck, a memory error detector
==11618== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11618== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==11618== Command: ./test -f ../cfg/test.yaml -D
==11618== Parent PID: 40502
==11618== 
==11618== Warning: client switching stacks?  SP change: 0x8a49a08 --> 0x5fde030
==11618==          to suppress, use: --max-stackframe=44480984 or greater
==11618== Warning: client switching stacks?  SP change: 0x8a48a58 --> 0x5fddb70
==11618==          to suppress, use: --max-stackframe=44478184 or greater
==11618== Warning: client switching stacks?  SP change: 0x7a47a08 --> 0x5fcada0
==11618==          to suppress, use: --max-stackframe=27774056 or greater
==11618==          further instances of this message will not be shown.
==11618== 
==11618== HEAP SUMMARY:
==11618==     in use at exit: 3,328 bytes in 16 blocks
==11618==   total heap usage: 17,489 allocs, 17,473 frees, 2,735,978 bytes allocated
==11618== 
==11618== 208 bytes in 1 blocks are definitely lost in loss record 1 of 2
==11618==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==11618==    by 0x96D62E: my_thread_init (my_thr_init.c:340)
==11618==    by 0x96D806: my_thread_global_init (my_thr_init.c:208)
==11618==    by 0x962B4E: my_init (my_init.c:104)
==11618==    by 0x95115B: mysql_server_init (libmysql.c:132)
==11618==    by 0x9474C6: mysql_init (client.c:1766)
==11618==    by 0x518CCF: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test/build/test)
==11618==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618== 
==11618== 3,120 bytes in 15 blocks are definitely lost in loss record 2 of 2
==11618==    at 0x4C2F7C8: calloc (vg_replace_malloc.c:1117)
==11618==    by 0x96D62E: my_thread_init (my_thr_init.c:340)
==11618==    by 0x951174: mysql_server_init (libmysql.c:183)
==11618==    by 0x9474C6: mysql_init (client.c:1766)
==11618==    by 0x518CCF: drogon::orm::MysqlConnection::MysqlConnection(trantor::EventLoop*, std::string const&) (in /home/fantasy/test/build/test)
==11618==    by 0x4BBD56: void __gnu_cxx::new_allocator<drogon::orm::MysqlConnection>::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4BAC6B: void std::allocator_traits<std::allocator<drogon::orm::MysqlConnection> >::construct<drogon::orm::MysqlConnection, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>&, drogon::orm::MysqlConnection*, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B9621: std::_Sp_counted_ptr_inplace<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B7C58: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(drogon::orm::MysqlConnection*&, std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B60F9: std::__shared_ptr<drogon::orm::MysqlConnection, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B44CE: std::shared_ptr<drogon::orm::MysqlConnection>::shared_ptr<std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::_Sp_alloc_shared_tag<std::allocator<drogon::orm::MysqlConnection> >, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618==    by 0x4B1E4E: std::shared_ptr<drogon::orm::MysqlConnection> std::allocate_shared<drogon::orm::MysqlConnection, std::allocator<drogon::orm::MysqlConnection>, trantor::EventLoop*&, std::string&>(std::allocator<drogon::orm::MysqlConnection> const&, trantor::EventLoop*&, std::string&) (in /home/fantasy/test/build/test)
==11618== 
==11618== LEAK SUMMARY:
==11618==    definitely lost: 3,328 bytes in 16 blocks
==11618==    indirectly lost: 0 bytes in 0 blocks
==11618==      possibly lost: 0 bytes in 0 blocks
==11618==    still reachable: 0 bytes in 0 blocks
==11618==         suppressed: 0 bytes in 0 blocks
==11618== 
==11618== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
 static auto end =
        std::shared_ptr<void>(nullptr, [](void *) {
        std::cout << "dddddddddddddddddddddddddddddddd---end" << std::endl;
mysql_library_end(); });
    mysql_init(mysqlPtr_.get())
--------------------------------------------------------------------------------------
^C2022-09-19T14:04:16.286183      Info: Shutting down...
dddddddddddddddddddddddddddddddd---end
Error in my_thread_global_end(): 16 threads didn't exit

nqf avatar Sep 19 '22 05:09 nqf

@an-tao It reduces some memory leak, but It still has memory leak, also need call mysql_thread_end

nqf avatar Sep 19 '22 05:09 nqf

https://dev.mysql.com/doc/refman/5.7/en/libmysqld.html

image

nqf avatar Sep 19 '22 05:09 nqf

void DbClientImpl::closeAll()
{
    std::lock_guard<std::mutex> lock(connectionsMutex_);
    for (auto const &conn : connections_)
    {
        conn->disconnect();
    }
    connections_.clear();
    readyConnections_.clear();
    busyConnections_.clear();
    // ------------------------------------------
    if (type_ == ClientType::Mysql) {
        for (int i = 0; i< loops_.size(); i++) {
            loops_.getLoop(i)->runInLoop([] {
                    mysql_thread_end();
            });
        }
    }
}

nqf avatar Sep 19 '22 06:09 nqf

https://dev.mysql.com/doc/c-api/5.7/en/mysql-init.html mysql-init not thread safe

nqf avatar Sep 19 '22 06:09 nqf

please check again, thanks.

an-tao avatar Sep 19 '22 09:09 an-tao

please check again, thanks. fixed @an-tao , If this fix is merged, could you create a new Release v1.8.1 ?

==21103== Memcheck, a memory error detector
==21103== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21103== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==21103== Command: ./test
==21103== Parent PID: 33977
==21103== 
==21103== Warning: client switching stacks?  SP change: 0x7a47a08 --> 0x5f2bf60
==21103==          to suppress, use: --max-stackframe=28424872 or greater
==21103== Warning: client switching stacks?  SP change: 0x8a49a08 --> 0x5fdf580
==21103==          to suppress, use: --max-stackframe=44475528 or greater
==21103== Warning: client switching stacks?  SP change: 0x7a46a58 --> 0x5f2baa0
==21103==          to suppress, use: --max-stackframe=28422072 or greater
==21103==          further instances of this message will not be shown.
==21103== 
==21103== HEAP SUMMARY:
==21103==     in use at exit: 0 bytes in 0 blocks
==21103==   total heap usage: 18,368 allocs, 18,368 frees, 2,483,665 bytes allocated
==21103== 
==21103== All heap blocks were freed -- no leaks are possible
==21103== 
==21103== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

nqf avatar Sep 20 '22 00:09 nqf

please check again, thanks. fixed @an-tao , If this fix is merged, could you create a new Release v1.8.1 ?

==21103== Memcheck, a memory error detector
==21103== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==21103== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==21103== Command: ./test
==21103== Parent PID: 33977
==21103== 
==21103== Warning: client switching stacks?  SP change: 0x7a47a08 --> 0x5f2bf60
==21103==          to suppress, use: --max-stackframe=28424872 or greater
==21103== Warning: client switching stacks?  SP change: 0x8a49a08 --> 0x5fdf580
==21103==          to suppress, use: --max-stackframe=44475528 or greater
==21103== Warning: client switching stacks?  SP change: 0x7a46a58 --> 0x5f2baa0
==21103==          to suppress, use: --max-stackframe=28422072 or greater
==21103==          further instances of this message will not be shown.
==21103== 
==21103== HEAP SUMMARY:
==21103==     in use at exit: 0 bytes in 0 blocks
==21103==   total heap usage: 18,368 allocs, 18,368 frees, 2,483,665 bytes allocated
==21103== 
==21103== All heap blocks were freed -- no leaks are possible
==21103== 
==21103== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Sure, thanks so much for yor feedback.

an-tao avatar Sep 20 '22 02:09 an-tao