[rabbitmq-discuss] tcp -> rabbitmq gives emfile + 541

Michael Nacos m.nacos at gmail.com
Tue Jun 30 09:31:41 BST 2009


Hi all and thank you for the Erlang Factory talks

I have tried to implement a very basic erlang tcp server which accepts
requests and forwards everything to rabbitmq exchanges. This is meant to be
a workaround the lack of a 0.8 C client, I am trying to get Postgresql to
send notifications through rabbitmq. Things work as expected up to a point,
until I get

{{badmatch,{error,emfile}},[{cinumber_daemon,connect,1}]}

followed by

Broker forced connection: 541 -> <<"INTERNAL_ERROR">>

I am pretty much an Erlang newbie, so please forgive me if this is not
really a rabbitmq issue. This could be useful to others, too.

cheers, Michael

Here is the relevant part of the code (I am certain recv_loop terminates):
recv_loop also does all the rabbity stuff (closes channel, closes
connection)

--------------------------------------------------------------------------------------------------

start_server() ->
    % start up the service and error out if we cannot
    case gen_tcp:listen(?LISTEN_PORT, ?TCP_OPTS) of
        {ok, Listen} ->
            spawn(?MODULE, connect, [Listen]),
            io:format("~p Server Started.~n", [erlang:localtime()]),
            sleep(infinity);
        Error ->
            io:format("Error: ~p~n", [Error])
    end.

connect(Listen) ->
    {ok, Socket} = gen_tcp:accept(Listen),
    inet:setopts(Socket, ?TCP_OPTS),
    % kick off another process to handle connections concurrently
    spawn(fun() -> connect(Listen) end),
    recv_loop(Socket),
    gen_tcp:close(Socket),
    exit(normal).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090630/16fef241/attachment.htm 


More information about the rabbitmq-discuss mailing list