[erlang-questions] process exits while calling gen_tcp:listen

Mikage Sawatari mikage@REDACTED
Fri Jan 11 04:21:04 CET 2008


Hello,

In some circumstances, calling gen_tcp:listen terminates the process
which called it.

Conditions are as follows:
- Start erl with -s option.
- Spawn the process by a process which has been spawned by supervisor.

This issue can be produced with the following code. I saw this issue
with R12B-0, Linux FedraCore1 (2.4.22) and Linux OpenSUSE 10.2.

%% listentest_sup.erl

-module(listentest_sup).
-behaviour(supervisor).

-export([start/0]).
-export([init/1]).

start() ->
        io:format("start supervisor~n"),
        supervisor:start_link({local, listentest}, listentest_sup, []).

init(_Args) ->
        {ok, {{one_for_one, 2, 10},
                [
                        {listentest, {listentest, start, []},
                                permanent, brutal_kill, worker, [listentest]}
                ]}}.

%% listentest.erl

-module(listentest).

-export([start/0]).
-export([listen/0]).


start() ->
        io:format("spawn listen process~n"),
        Pid = proc_lib:spawn_link(?MODULE, listen, []),
        {ok, Pid}.

listen() ->
        io:format("call gen_tcp:listen~n"),
        Res = gen_tcp:listen(7725, []),
        io:format("listen: ~p~n", [Res]).

%%%%


The program is supposed to print "listen: ~p~n" but in the first
execution example it doesn't print it.

Without supervisor, or without -s option, the process reaches the next
line of gen_tcp:listen.

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

$ erl -boot start_sasl -s listentest_sup start
Erlang (BEAM) emulator version 5.6 [source] [async-threads:0] [hipe]
[kernel-poll:false]


=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
         application: sasl
          started_at: nonode@REDACTED
start supervisor
spawn listen process
call gen_tcp:listen

=PROGRESS REPORT==== 11-Jan-2008::09:57:20 ===
          supervisor: {local,listentest}
             started: [{pid,<0.40.0>},
                       {name,listentest},
                       {mfa,{listentest,start,[]}},
                       {restart_type,permanent},
                       {shutdown,brutal_kill},
                       {child_type,worker}]
Eshell V5.6  (abort with ^G)
1>

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

$ erl -boot start_sasl -s listentest start
Erlang (BEAM) emulator version 5.6 [source] [async-threads:0] [hipe]
[kernel-poll:false]


=PROGRESS REPORT==== 11-Jan-2008::09:58:24 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:58:24 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:58:24 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:58:24 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:58:24 ===
         application: sasl
          started_at: nonode@REDACTED
spawn listen process
call gen_tcp:listen
listen: {ok,#Port<0.96>}
Eshell V5.6  (abort with ^G)
1>

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

$ erl -boot start_sasl
Erlang (BEAM) emulator version 5.6 [source] [async-threads:0] [hipe]
[kernel-poll:false]


=PROGRESS REPORT==== 11-Jan-2008::09:59:27 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:59:27 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:59:27 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:59:27 ===
(snipped)

=PROGRESS REPORT==== 11-Jan-2008::09:59:27 ===
         application: sasl
          started_at: nonode@REDACTED
Eshell V5.6  (abort with ^G)
1> listentest_sup:start().
start supervisor
spawn listen process
call gen_tcp:listen

=PROGRESS REPORT==== 11-Jan-2008::09:59:37 ===
          supervisor: {local,listentest}
             started: [{pid,<0.42.0>},
                       {name,listentest},
                       {mfa,{listentest,start,[]}},
                       {restart_type,permanent},
                       {shutdown,brutal_kill},
                       {child_type,worker}]
{ok,<0.41.0>}
listen: {ok,#Port<0.106>}
spawn listen process
(snipped)



-- 
-----------------------------------------------------------------------
SAWATARI Mikage (SANO Taku)



More information about the erlang-questions mailing list