[erlang-questions] tcp connections dropped in gen_server

Reynaldo Baquerizo reynaldomic@REDACTED
Wed Sep 7 19:33:39 CEST 2011


>>> It makes very little sense to restart these processes (to me), because
>>> the TCP connection will die as well. The external client can reconnect
>>> and start anew. Or am I missing something?
>>
>> Indeed, the client will reconnect. But I think I found the problem. The
>> process that is listening for new connections in gen_tcp:accept/1 dies
>> at some point, all other processes with established connections are fine
>> but eventually crash (cause of bad input), no further reconnections
>> will be possible.
>
> I see. Can you provide us with the exact cause of it (i.e. what
> gen_tcp:accept/1 returned)? It seems to me that under normal
> operation (if the accept was successful at least once before),
> there should be no problem of this kind...

Achh,, found it (think so)
I've hit the ERL_MAX_PORTS limit

Log Report:

=CRASH REPORT==== 7-Sep-2011::10:42:53 ===
  crasher:
    initial call: comm_tcp:acceptor/2
    pid: <0.1833.0>
    registered_name: []
    exception error: no match of right hand side value {error,enfile}
      in function  comm_tcp:acceptor/2
    ancestors: [comm_client_sup,comm_sup,<0.51.0>]
    messages: []
    links: [<0.61.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 233
    stack_size: 24
    reductions: 96
  neighbours:

=SUPERVISOR REPORT==== 7-Sep-2011::10:42:53 ===
     Supervisor: {local,comm_client_sup}
     Context:    child_terminated
     Reason:     {badmatch,{error,enfile}}
     Offender:   [{pid,<0.1833.0>},
                  {name,comm_tcp},
                  {mfargs,{comm_tcp,start_link,undefined}},
                  {restart_type,temporary},
                  {shutdown,brutal_kill},
                  {child_type,worker}]

For further reference I am running Erlang on a Windows Server 2008.

Besides setting ERL_MAX_PORTS to a higher number, any other suggestion?
I have already found this thread
http://erlang.2086793.n4.nabble.com/error-emfile-on-windows-td3064840.html
 in case anyone else find it useful.




>> How can I isolate the listening process? or reestructure to restart it
>> if it crashes?
>
> You need to restructure the processes then:
>
>    port (service) supervisor - one_to_one
>        acceptor - worker
>        session supervisor - simple_one_to_one
>            connection - worker

I don't want to augment the complexity, I will tune ERL_MAX_PORTS and
handle the exhaustion with a case clause to avoid terminating the
process.

Thanks for the lengthy explanation

>
> If you have further questions, please do not hesitate and ask! :-)

I will.

--
Reynaldo



More information about the erlang-questions mailing list