Terminating application during startup

Fredrik Thulin ft@REDACTED
Tue Mar 21 14:59:32 CET 2006


Hi

I have a problem with getting my application to terminate nicely when an 
error occurs during startup. I have done some serious testing here and 
discovered that the problem is with reason strings longer than exactly 
30 characters.

The problem can be seem with the attached example application, compiled 
like this :

  $ /pkg/erlang/R10B-10/bin/erlc my.erl
  $ /pkg/erlang/R10B-10/bin/erlc my.rel

Booting 'my' with '-extra short' works (meaning the erlang VM 
terminates), '-extra long' gives an ugly error message and the erlang 
VM never terminates!


$ /pkg/erlang/R10B-10/bin/erl -boot my -noshell -extra short

=INFO REPORT==== 21-Mar-2006::14:48:14 ===
    application: my
    exited: {"123456789012345678901234567890",{my,start,[normal,[foo]]}}
    type: permanent
{"Kernel pid 
terminated",application_controller,"{application_start_failure,my,
{[49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48],
{my,start,[normal,[foo]]}}}"}

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) 
({application_start_failure,my,
{[49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48],
{my,start,[normal,[foo]]}}})

$ /pkg/erlang/R10B-10/bin/erl -boot my -noshell -extra long

=INFO REPORT==== 21-Mar-2006::14:48:19 ===
    application: my
    exited: {"1234567890123456789012345678901",{my,start,[normal,
[foo]]}}
    type: permanent
{"Kernel pid 
terminated",application_controller,"{application_start_failure,my,
{[49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49],
{my,start,[normal,[foo]]}}}"}
{error_logger,{{2006,3,21},{14,48,21}},'~s~n',['Error in process <0.0.0> 
with exit value: {badarg,[{erlang,halt,["Kernel pid terminated 
(application_controller) ({application_start_failure,my,
{[49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49,50,51,52,53,54,55,56,57,48,49],
{m... \n']}


/Fredrik

PS. Does anyone have alternate suggestions about how to get your 
application to terminate on startup problems? The '-extra short' output 
isn't very appealing either with the big "Kernel pid terminated" tuple 
outputted. I'd rather not have an erl_crash.dump file written for all 
occasions either. Non-zero exit-status is necessary.
-------------- next part --------------
{application, my,
 [{description, "Test app"},
  {vsn,"0.0"},
  {modules, [
	     my
	    ]},
  {registered, []},
  {mod, {my, [foo]}},
  {env, []},
  {applications,
        [kernel, stdlib]}]}.
-------------- next part --------------
-module(my).

-export([start/2]).

start(normal, [foo]) ->
    case init:get_plain_arguments() of
	["short"] ->
	    {error, "123456789012345678901234567890"};
	["long"] ->
	    {error, "1234567890123456789012345678901"}
    end.
-------------- next part --------------
{release, {"Test app","0.0"}, {erts, "5.2"},
 [{kernel,"2.10.13"},
  {stdlib,"1.13.12"},
  {ssl, "3.0.11"},
  {mnesia, "4.2.5"},
  {my, "0.0"}
 ]}.


More information about the erlang-questions mailing list