wangboo/erlang-mysql-driver

mysql_conn:start race condition

Opened this issue · 0 comments

I run in to race condition trouble while using mysql_conn:start/7.
I just begun to receive "unknown signal received" error messages simetimes.

As I understood problem is in this part of mysql_conn module:

start(Host, Port, User, Password, Database, LogFun, PoolId) ->
    ConnPid = self(),
    Pid = spawn(fun () ->
            init(Host, Port, User, Password, Database,
                 LogFun, PoolId, ConnPid)
        end),
    post_start(Pid, LogFun).
...

%% part of start/6 or start_link/6:
post_start(Pid, LogFun) ->
    receive
    {mysql_conn, Pid, ok} ->
        {ok, Pid};
    {mysql_conn, Pid, {error, Reason}} ->
        {error, Reason};
    Unknown ->
        ?Log2(LogFun, error,
         "received unknown signal, exiting: ~p", [Unknown]),
        {error, "unknown signal received"}
    after 5000 ->
        {error, "timed out"}
    end.

Function post_start executes in context of calling process. 
And it is possible that this process will recieve other messages from 
other processes and in this case it will generate error "unknown signal 
received".
As a workaround now I just commented out Unknown case in receieve. Another 
possibility is creating temporal process from which call mysql_conn:create.
But I think it's unnecessary complication.
--
Mikl

Original issue reported on code.google.com by mkur...@gmail.com on 18 Sep 2007 at 11:16