lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
535 stars 192 forks source link

fixing leak of mysql thread handlers #69

Closed tomatolog closed 7 years ago

tomatolog commented 7 years ago

fixing issue #22. I see that there is no either mysql_library_end or mysql_server_end that should free resource handler allocated by mysql_init That is why when use library with Apache that fork child and keep child alive reusing library at lua scripts cause leak of thread handlers and error LuaSQL: error connecting: Out of memory. along with libmysqlclient library error Can't initialize threads: error 11

and following stack obtained with strace libmysqlclient.so(my_thread_global_init libmysqlclient.so(my_init libmysqlclient.so(mysql_server_init libmysqlclient.so(mysql_init mysql.so(env_connect luajit(luaL_openlibs

tomasguisasola commented 7 years ago

Hi

I've read in the docs that

"... mysql_server_end() is deprecated and mysql_library_end()
 should be used instead"

Do you have a reason to use mysql_server_end() ? Or should I change it to mysql_library_end() ?

Regards, Tomás

On 2017-01-10 08:18, Stas wrote:

fixing issue #22 [1]. I see that there is no either mysql_library_end or mysql_server_end that should free resource handler allocated by mysql_init That is why when use library with Apache that fork child and keep child alive reusing library at lua scripts cause leak of thread handlers and error LuaSQL: error connecting: Out of memory. along with libmysqlclient library error Can't initialize threads: error 11

and following stack obtained with strace libmysqlclient.so(my_thread_global_init libmysqlclient.so(my_init libmysqlclient.so(mysql_server_init libmysqlclient.so(mysql_init mysql.so(env_connect luajit(luaL_openlibs

YOU CAN VIEW, COMMENT ON, OR MERGE THIS PULL REQUEST ONLINE AT:

https://github.com/keplerproject/luasql/pull/69 [2]

COMMIT SUMMARY

  • fixing leak of mysql thread handlers

FILE CHANGES

  • M src/ls_mysql.c [3] (1)

PATCH LINKS:

-- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub [2], or mute the thread [6].

*

Links:

[1] https://github.com/keplerproject/luasql/issues/22 [2] https://github.com/keplerproject/luasql/pull/69 [3] https://github.com/keplerproject/luasql/pull/69/files#diff-0 [4] https://github.com/keplerproject/luasql/pull/69.patch [5] https://github.com/keplerproject/luasql/pull/69.diff [6] https://github.com/notifications/unsubscribe-auth/AAIA7Yl_-yPyfflhyy6f2J5YfhMDWVMWks5rQ1r8gaJpZM4LfPZB

tomatolog commented 7 years ago

Yes, it worth to use mysql_library_end instead of mysql_server_end. at my version of libmysqlclient they both means same via such define

define mysql_library_end mysql_server_end

tomatolog commented 7 years ago

I've made commit that replaces mysql_server_end() with mysql_library_end() function. Also wanted to notice that mysql_library_end() requires MySQL at least version 4.1.10. For previous versions someone should use mysql_server_end() instead

I also might try to made you docker setup and scripts that reproduce issue from #22

agladysh commented 7 years ago

@tomasguisasola any news about this?

tomasguisasola commented 7 years ago

Hi Alexander

Sorry, but I am too busy :-(

Regards, Tomás

On 2017-01-17 16:53, Alexander Gladysh wrote:

@tomasguisasola [1] any news about this?

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or mute the thread [3].

*

Links:

[1] https://github.com/tomasguisasola [2] https://github.com/keplerproject/luasql/pull/69#issuecomment-273262827 [3] https://github.com/notifications/unsubscribe-auth/AAIA7QPXxLy5YK9ov28-psTqxJ2Jsna2ks5rTQ5CgaJpZM4LfPZB