[erlang-questions] terminate() not finishing after application:stop()

Gijsbert de Haan gijsbert_de_haan@REDACTED
Tue Jun 10 16:12:33 CEST 2008


The process is indeed trapping exits.
I see my debug io:format() from my terminate() function before the call
to xmerl:export/3, but not the ones after. In the following code
(edited) I see 'before_xmerl_export', but nothing after (related to that
process):

terminate(Reason, State) ->
    ?D(Reason),
    {memory, Memory} = erlang:process_info(self(), memory),
    error_logger:info_msg(
      "~p session '~s' memory usage ~B\n", [self(), Name, Memory]),
    Prolog = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>"],
    ?D(Prolog),
    Xml = getXml(State),
    ?D(before_xmerl_export),
    try xmerl:export(
          [Xml],
          xmerl_xml,
          [#xmlAttribute{name = prolog, value = Prolog}]) of
        StrData ->
            ?D(before_list_to_binary),
            Data = list_to_binary(StrData),
            case file:write_file(Name2, Data) of
                ok ->
                    error_logger:info_msg("~p session '~s' saved\n",
                                          [self(), Name2]);
                {error, Error} ->
                    error_logger:error_msg(
                      "~p session '~s' NOT saved\nError ~p\n",
                      [self(), Name2, Error])
            end
    catch
        throw:X -> ?D(throw), ?D(X);
          exit:X -> ?D(exit), ?D(X);
          error:X -> ?D(error), ?D(X)
    end,
    ok.

On Tue, 10 Jun 2008 15:45:51 +0200, "Ulf Wiger (TN/EAB)"
<ulf.wiger@REDACTED> said:
> 
> Make sure your process is trapping exits.
> If it isn't, the process will die immediately when
> the supervisor calls exit(Pid, shutdown).
> 
> BR,
> Ulf W
> 
> Gijsbert de Haan skrev:
> > Hi,
> > 
> > I have an application that I want to stop. In terminate() of one of the
> > processes I save some state to an xml file (with xmerl:export() and
> > file:write_file()). When this process terminates by itself all is well,
> > and the file is saved.
> > But when I call application:stop(myapp) the call to xmerl:export() (in
> > terminate) never returns and the state is not saved. There are no error
> > reports in the log, just the usual info report about myapp having
> > exited. I have put a try/catch (throw/exit/error) around the
> > xmerl:export() with some io:format() calls but nothing comes out.
> > 
> > Anybody have a suggestion?
> > Thanks,
> > Gijsbert
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list