[erlang-questions] How to detect that spawn/4 did not work

Fred Hebert <>
Fri Aug 8 22:35:07 CEST 2014


On 08/08, Federico Carrone wrote:
> Well with spawn link it generates an ** exception exit: noconnection.
> However I still think it is strange that spawn/4 returns a Pid even when it
> is not working.
> 
> On Fri, Aug 8, 2014 at 5:06 PM, Federico Carrone <
> > Why does it return a pid even if it did not work and if it can detect the
> > error (since it generated an error report)?
> >

The question to ask is what do you do if it doesn't work?
The follow-up question to ask is what do you do if it works, but fails a microsecond later?

What about 2,3,N microseconds?

The spawn function calls are asynchronous. Whether they fail at creation
or a microsecond later has little effect. What counts is that you detect
the failure and it happened at some point (if you care about it).

How differently can you handle a failure before the initialization,
while it is taking place (but before the first function call succeeded),
halfway through a chain of calls, or after it was done? How do you know
when exactly it failed?

What if the noconnect (split) happened after you indeed got the Pid, but
before code could be run?

You'll find out there is very little difference in what you can do as
the spawner whether it managed to spawn or not, and the lack of
atomicity may just mean it's as sensible to do what Erlang does right
now than greedy detection.

In practice, what you're gonna lose is granularity in what you get as a
report, but nothing different from the worst case you will *have* to
consider anyway when deciding how to handle your errors.
If you can deal with the worst case, then the rest is not that bad.

Regards,
Fred.



More information about the erlang-questions mailing list