wangboo/erlang-mysql-driver

mysql connection leak on error

Opened this issue · 1 comments

I was playing with the driver and noticed when the main mysql module timed
out during a connection the main process would exit with an error but the
mysql_conn process stayed around and held the mysql connection open... the
following seems to fix it

Index: src/mysql_conn.erl
===================================================================
--- src/mysql_conn.erl  (revision 27)
+++ src/mysql_conn.erl  (working copy)
@@ -145,7 +145,7 @@
 %%--------------------------------------------------------------------
 start(Host, Port, User, Password, Database, LogFun, PoolId) ->
     ConnPid = self(),
-    Pid = spawn(fun () ->
+    Pid = spawn_link(fun () ->
                        init(Host, Port, User, Password, Database,
                             LogFun, PoolId, ConnPid)
                end),
Index: src/mysql.erl
===================================================================
--- src/mysql.erl       (revision 27)
+++ src/mysql.erl       (working copy)
@@ -679,7 +679,7 @@
     end.

 start_reconnect(Conn, LogFun) ->
-    Pid = spawn(fun () ->
+    Pid = spawn_link(fun () ->
                        reconnect_loop(Conn#conn{pid = undefined}, LogFun, 0)
                end),
     {PoolId, Host, Port} = {Conn#conn.pool_id, Conn#conn.host,
Conn#conn.port},

Original issue reported on code.google.com by jla...@gmail.com on 27 Oct 2006 at 10:00

If this solve the problem and it does look like it, who should add it in the 
repo?

Original comment by JLdeBr...@gmail.com on 19 Jan 2011 at 8:38