Trapped exits

Olivier BOUDEVILLE olivier.boudeville@REDACTED
Wed Feb 16 18:13:47 CET 2011


Hi,

I just have been bitten by the fact that apparently the code executed 
through "erl -eval" or "erl -run" will be executed by a process silently 
trapping exits by default (the opposite of when running it from the shell 
and of the default for spawned processes). 

Indeed, with:
"""
-module(foobar).
-export([ run/0 ]).
run() ->
      io:format( "Process ~w: ~p", [self(),process_info(self(),trap_exit)] 
).
"""

>From the shell we have as expected:
"""
> erl
Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:8:8] [rq:8] 
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.2  (abort with ^G)
1> c(foobar).
{ok,foobar}
2> foobar:run().
Process <0.31.0>: {trap_exit,false}ok
"""

whereas:

"""
> erl -eval 'foobar:run()'
Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:8:8] [rq:8] 
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.2  (abort with ^G)
1> Process <0.2.0>: {trap_exit,true}
"""

and 

"""
> erl -run foobar run
Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:8:8] [rq:8] 
[async-threads:0] [hipe] [kernel-poll:false]

Process <0.2.0>: {trap_exit,true}Eshell V5.8.2  (abort with ^G)
"""

Maybe I have missed some references, but it does not seem much advertised!

And why trapping exits by default? Wouldn't it be safer to crash the 
spawned "initialization process" instead?

That means that when executing other processes in run/0, even thanks to 
spawn_link, EXIT messages might happily wait in the message queue of the 
run process and possibly remain unnoticed; a default policy which somewhat 
seems to violate both the "crash early" and "least astonishment" 
principles. Unless I made a mistake somewhere?

Thanks in advance for any hint,
Best regards,

Olivier Boudeville.
---------------------------
Olivier Boudeville

EDF R&D : 1, avenue du Général de Gaulle, 92140 Clamart, France
Département SINETICS, groupe ASICS (I2A), bureau B-226
Office : +33 1 47 65 59 58 / Mobile : +33 6 16 83 37 22 / Fax : +33 1 47 
65 27 13



Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus.
____________________________________________________

This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or virus-free.


More information about the erlang-questions mailing list