application:stop hangs

Lennart Öhman <>
Fri May 25 13:23:21 CEST 2001


Taking a risk when entering into a correspondence I have not followed...
In the first place proc_lib was (a long time ago) built as a layer
between gen_server (or server_lib at that time) for those who needed
to build (OTP)compliant processes but without using server_lib. At
that time there were no gen_event, gen_fsm etc.

At that time there were no applications-concept making it sometimes
necessary
to start processes as top-most-supervisor linked to nothing.

If you like the spawning and linking to be atomic it must be done
through
a call to spawn_link/3. Since having all API functions (including the
start
function) in the code which implements the server is a really good idea,
it must
be the server code which calls spawn_link/3 (instead of making it the
responsibility
of the supervisor to link). Then there must be two gen_server or
proc_lib
functions to provide both options (unlinked for shell testing or other
situations
where linking to the caller is no good, and regular linked). You must
just hope
that the server programmer uses the correct one for the situation the
server
is going to be started in.

/Lennart



Ulf Wiger wrote:
> 
> On Thu, 24 May 2001, Chandrashekhar Mullaparthi wrote:
> 
> >After a bit more digging - there was no link between my worker process and
> >the supervisor!! I was using proc_lib:spawn. I used proc_lib:spawn_link and
> >everything works fine.
> >
> >I had assumed that the supervisor will link to all it's children - it seems
> >to be the other way round. Why does the supervisor not link explicitly - it
> >would be quite handy!
> 
> We've had discussions about this for quite some time. It's not
> backward compatible, nor does it completely solve the problem, to
> have the supervisor link to the child automatically. I *have*
> seen at least one case where the child has explicitly called
> unlink(Parent) (!). I was told that the reason had to do with
> some special test method from the Erlang shell(*), and that they
> had forgotten to take it out...
> 
> (*) Actually, if you start a gen_server using start_link from the
> shell, you'd better explicitly unlink it -- if you mistype a
> command and the shell process crashes (which happens pretty
> often), your server will die as well.
> 
> The solution should be to have the supervisor rely on monitors
> instead of links for the shutdown protocol.
> 
> I've patched supervisor.erl with the following code.
> It seems to work for me.
> 
> /Uffe
> 

-------------------------------------------------------------
Lennart Ohman                   phone   : +46-8-587 623 27
Sjoland & Thyselius Telecom AB  cellular: +46-70-552 6735
Sehlstedtsgatan 6               fax     : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN     email   : 



More information about the erlang-questions mailing list