saleyn / erlexec

Execute and control OS processes from Erlang/OTP
https://hexdocs.pm/erlexec/readme.html
Other
541 stars 141 forks source link

Not killing a process trapping SIGTERM #32

Closed davidw closed 10 years ago

davidw commented 10 years ago

This bash script:

#!/bin/bash

rm -f /tmp/lpr

trap 'echo vampire_process_wont_die >> /tmp/lrp' SIGINT SIGTERM

while [ true ] ;
 do date >> /tmp/lrp
    sleep 1
done

Doesn't get killed by exec in a clean way.

exec:start(),
{ok, Pid, _} = exec:run("./lrp.sh", []),
timer:sleep(1000),
exec:stop(Pid).
davidw commented 10 years ago

https://github.com/davidw/erlexec/commit/d1f03c6afb1d99c06785ac380ce0f537807c8887 is one problem, but that's not the entire story...

davidw commented 10 years ago

Now it's stopping things, but it still generates this:

=ERROR REPORT==== 28-Apr-2014::15:30:49 ===
** Generic server exec terminating 
** Last message in was {port,{stop,<0.42.0>}}
** When Server state == {state,#Port<0.2547>,0,{[],[]},[],exec_mon,false}
** Reason for termination == 
** {{case_clause,[{<0.42.0>,26914}]},
    [{exec,is_port_command,3,[{file,"src/exec.erl"},{line,816}]},
     {exec,handle_call,3,[{file,"src/exec.erl"},{line,526}]},
     {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,585}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
** exception exit: {{{case_clause,[{<0.42.0>,26914}]},
                     [{exec,is_port_command,3,
                            [{file,"src/exec.erl"},{line,816}]},
                      {exec,handle_call,3,[{file,"src/exec.erl"},{line,526}]},
                      {gen_server,handle_msg,5,
                                  [{file,"gen_server.erl"},{line,585}]},
                      {proc_lib,init_p_do_apply,3,
                                [{file,"proc_lib.erl"},{line,239}]}]},
                    {gen_server,call,[exec,{port,{stop,<0.42.0>}},30000]}}
     in function  gen_server:call/3 (gen_server.erl, line 188)
davidw commented 10 years ago

This seems to help avoid that crash:

https://github.com/davidw/erlexec/commit/f2ff5dbc995ef63687323790e40a1c9b84f74cfd

saleyn commented 10 years ago

Thanks. Could you do a pull request?

davidw commented 10 years ago

Merged.