<div>I added some codes to stop the receiver and sender's supervisor, and also sleep(500) before calling erlang:halt()</div><div>But the problem remains.<span id="_editor_bookmark_start_3" style="display: none; line-height: 0px;"></span></div><div><br></div><div><b>[gs_gateway.erl]</b></div><div>...</div><div><div>stop() -></div><div> supervisor:terminate_child(gs_sup, gs_tcp_client_sup),</div><div> supervisor:terminate_child(gs_sup, gs_tcp_listener_sup),</div><div> timer:sleep(500),</div><div> io:format("gs_gateway stop~n"),</div><div> ok.<span id="_editor_bookmark_start_0" style="display: none; line-height: 0px;"></span></div></div><div><br></div><div>The gs_tcp_client_sup is the supervisor which supervises the receiver process:</div><div><b>[<span style="line-height: 1.5;">gs_tcp_client_sup.erl<span id="_editor_bookmark_start_2" style="display: none; line-height: 0px;"></span></span><span style="line-height: 1.5;">]</span></b></div><div><div>...</div><div>start_link(Mod) -></div><div> supervisor:start_link({local,?MODULE}, ?MODULE, [Mod]).</div><div>init([Mod]) -></div><div> {ok, {{simple_one_for_one, 10, 10},</div><div> [{Mod, {Mod, start_link, []},</div><div> temporary, <b>brutal_kill</b>, worker, [Mod]}]}}.<span id="_editor_bookmark_start_1" style="display: none; line-height: 0px;"></span></div></div><div><br></div><div>Since I use 'brutal_kill' option, the receiver process will be killed immediately while the gs_tcp_client_sup is terminated.</div><div>In this case it doesn't call <span style="line-height: 1.5;">gen_tcp:close(Socket) </span><span style="line-height: 1.5;">in the receiver process obviously.</span></div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">It is true that my 'gateway' node may has some bug , though it is working normally.</span></div><div><span style="line-height: 1.5;">When I strace the normal working 'gateway' node, it shows there are lots of 'recvfrom' errors increasing by time:</span></div><div><span style="line-height: 1.5;"><div><b>[root@localhost scripts]# strace -c -p 21376</b></div><div>Process 21376 attached - interrupt to quit</div><div>^CProcess 21376 detached</div><div>% time seconds usecs/call calls errors syscall</div><div>------ ----------- ----------- --------- --------- ----------------</div><div> 94.61 0.004370 2 1988 epoll_wait</div><div> 1.91 0.000088 1 61 writev</div><div> 1.28 0.000059 1 107 times</div><div> 1.28 0.000059 1 118 epoll_ctl</div><div> 0.93 0.000043 0 105 15 <b>recvfrom</b></div><div>------ ----------- ----------- --------- --------- ----------------</div><div>100.00 0.004619 2379 15 total</div><div><b>[root@localhost scripts]# strace -p 21376 -e 'recvfrom'</b></div><div>Process 21376 attached - interrupt to quit</div><div>recvfrom(28, "\0\0\0\16N!", 6, 0, NULL, NULL) = 6</div><div>recvfrom(28, "\0\0\0\307\0\3\r\252", 8, 0, NULL, NULL) = 8</div><div>recvfrom(28, 0x7fac5a3d5e00, 6, 0, 0, 0) = <b>-1 EAGAIN (Resource temporarily unavailable)</b></div><div>recvfrom(23, "\0\0\0\204\203D\3\5\2D\5\350h\3a\2R\1gR\0\0\0\0\314\0\0\0\0\1h\2"..., 1460, 0, NULL, NULL) = 136</div><div>recvfrom(23, "\0\0\0001\203D\3\5\2D\5\350h\3a\2R\1gR\0\0\0\0\314\0\0\0\0\1h\2"..., 1460, 0, NULL, NULL) = 53</div><div>recvfrom(28, "\0\0\0\31N\"", 6, 0, NULL, NULL) = 6</div><div>recvfrom(28, "\0\0\0\0\0\0\0006\0\3dev\0\1\0\3\16\v", 19, 0, NULL, NULL) = 19</div><div>recvfrom(28, 0x7fac5a3d5e00, 6, 0, 0, 0) = <b>-1 EAGAIN (Resource temporarily unavailable)</b></div><div>recvfrom(23, "\0\0\0V\203D\3\5\2D\5\350h\3a\2R\1gR\0\0\0\0\314\0\0\0\0\1h\2"..., 1460, 0, NULL, NULL) = 170</div><div>recvfrom(28, "\0\0\0\16N!", 6, 0, NULL, NULL) = 6</div><div>recvfrom(28, "\0\0\0\307\0\3\r\251", 8, 0, NULL, NULL) = 8</div><div>recvfrom(28, 0x7fac5a3d5e00, 6, 0, 0, 0) = <b>-1 EAGAIN (Resource temporarily unavailable)</b></div><div>...</div><div><br></div><div>But I don't know how to dig deeper here to find out why there are recvfrom errors.</div></span></div><div><span style="line-height: 1.5;">In additional, I use the pstack command to detect the stack of the fack dead 'gateway' node which is not exit normally:</span></div><div><span style="line-height: 1.5;"><div><b>[root@localhost scripts]# pstack 27304</b></div><div>#0 0x0000000000496233 in erts_deliver_time ()</div><div>#1 0x000000000051ce2c in erts_check_io_kp ()</div><div>#2 0x0000000000516a4d in erl_sys_schedule ()</div><div>#3 0x000000000048d406 in schedule ()</div><div>#4 0x00000000004fcb34 in process_main ()</div><div>#5 0x0000000000450fd5 in erl_start ()</div><div>#6 0x0000000000435add in main ()<span id="_editor_bookmark_start_4" style="display: none; line-height: 0px;"></span></div><div><div><b>[root@localhost scripts]# pstack 27304</b></div><div>#0 0x000000000051bf2d in erts_poll_interrupt_kp ()</div><div>#1 0x000000000048d431 in schedule ()</div><div>#2 0x00000000004fcb34 in process_main ()</div><div>#3 0x0000000000450fd5 in erl_start ()</div><div>#4 0x0000000000435add in main ()<span id="_editor_bookmark_start_5" style="display: none; line-height: 0px;"></span></div></div><div><br></div><div>It seems that the erlang scheduler is still working after erlang:halt().</div><div>So, any new suggestion?</div><div>Thanks~</div><div><br></div></span></div><div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "Imants Cekusins";<imantc@gmail.com>;</div><div><b>Date: </b> Thu, Nov 13, 2014 07:35 AM</div><div><b>To: </b> "adam chan"<114999420@qq.com>; <wbr></div><div><b>Cc: </b> "erlang-questions"<erlang-questions@erlang.org>; <wbr></div><div><b>Subject: </b> Re: [erlang-questions] A problem with exit erlang node.</div></div><div><br></div><p dir="ltr">Could the 'gateway' node close its open sockets before shutting down?</p>
<p dir="ltr">Maybe pause for a second after pinging an exit signal to the gateway node, stopping the apps but before calling erlang:halt()?</p>
<div class="gmail_quote">On 12 Nov 2014 17:14, "adam chan" <<a href="mailto:114999420@qq.com">114999420@qq.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi List,</div><div><br></div><div>I have a problem to stop or exit a erlang node.<span style="line-height:0px"></span></div><div>When I called erlang:halt(), the node is fake dead, and the cpu goes up to 100%.</div><div><br></div><div>Here is the situation:</div><div>I'm running OTP_R15B02 on Centos 6.3.<span style="line-height:0px"></span></div><div><br></div><div>I have 3 nodes named 'server', 'unite' and 'gateway' which connected to each other.</div><div>The 'gateway' node listens to a port , receives socket datas from client, and then transfers to 'server' and 'unite'. </div><div>The response data from 'server' and 'unite' will send back to client through 'gateway' node too.</div><div> </div><div>When I want to stop all these 3 nodes, the 'gateway' node CAN NOT exit completely sometimes <span style="line-height:1.5">(small probability</span><span style="line-height:1.5">) <span style="line-height:0px"></span></span><span style="line-height:1.5">.</span></div><div>The nodes is running in screen of linux, the starting scripts like this:</div><div><br></div><div><b>[start_all.sh]</b></div><div>...</div><div>/usr/bin/screen -dmS server -s $ScriptPath/start_server.sh $Log<span style="line-height:0px"></span><span style="line-height:0px"></span></div><div>...</div><div>/usr/bin/screen -dmS unite -s $ScriptPath/start_unite.sh $Log<span style="line-height:0px"></span></div><div>...</div><div>/usr/bin/screen -dmS gateway -s $ScriptPath/start_gateway.sh $Log<span style="line-height:0px"></span></div><div><br></div><div><b>[start_gateway.sh]</b></div><div><div>#!/bin/bash</div><div>cd /data/web/server/server/config</div><div>ulimit -s 262140</div><div>erl -kernel inet_dist_listen_min 40001 -kernel inet_dist_listen_max 40100 +P 1024000 +K true -smp disable -name <a href="mailto:gateway@192.168.7.100" target="_blank">gateway@192.168.7.100</a> -setcookie abc -boot start_sasl -config gs_main -pa ../ebin -s gs_main start -extra 192.168.7.100<span style="line-height:0px"></span> 9001 2</div></div><div><br></div><div><br></div><div>I stop the nodes in the order of 'gateway' -> 'unite' -> 'server'</div><div>The stop scripts like this:</div><div><b>[stop_all.sh]</b></div><div><div>#!/bin/bash</div><div>cd /data/web/server/server/scripts/</div><div>chmod +x stop_gateway.sh</div><div>chmod +x stop_unite.sh</div><div>chmod +x stop_server.sh</div><div>./stop_gateway.sh</div><div>./stop_unite.sh</div><div>./stop_server.sh<span style="line-height:0px"></span></div></div><div><br></div><div><b>[stop_gateway.sh]</b></div><div><div>#!/bin/bash</div><div>cd /data/web/server/server/config</div><div>erl -noshell -hidden -name <a href="mailto:stop_gateway@192.168.7.100" target="_blank">stop_gateway@192.168.7.100</a> -setcookie abc -pa ../ebin -eval "rpc:call('<a href="mailto:gateway@192.168.7.100" target="_blank">gateway@192.168.7.100</a>', gs_main, stop, [])." -s c q<span style="line-height:0px"></span></div></div><div><br></div><div><b>[gs_main.erl]</b></div><div>-define(SERVER_APPS, [sasl, gs_main]).<span style="line-height:0px"></span></div><div>...</div><div><div>stop() -></div><div> ok = stop_applications(?SERVER_APPS),</div><div> erlang:halt().<span style="line-height:0px"></span></div></div><div><br></div><div><br></div><div>The 'server' and 'unite' node can exit completely every time, and the screen which is running the node also exit too.</div><div>But the 'gateway' node sometimes (small probability<span style="line-height:0px"></span><span style="line-height:1.5">) can't exit, the screen remains too:</span></div><div><span style="line-height:1.5"><br></span></div><div><div style="line-height:1.5"><b>[root@localhost logs]# screen -ls</b></div><div style="line-height:1.5">There are screens on:</div><div style="line-height:1.5"> 20107.gateway (Detached)</div><div style="line-height:1.5"><br></div><div style="line-height:1.5"><div><b>[root@localhost logs]# ps -ef | grep gateway</b></div><div>root 20107 1 0 Nov10 ? 00:00:00 /usr/bin/SCREEN -dmS gateway -s /data/web/server/server/scripts/start_gateway.sh -L -c /data/web/server/server/var/logs/screenrc_gateway</div><div>root 20110 20107 0 Nov10 pts/7 00:00:00 /bin/bash /data/web/server/server/scripts/start_gateway.sh</div><div>root 20111 20110 90 Nov10 pts/7 1-19:56:53 /usr/local/lib/erlang/erts-5.9.2/bin/beam -P 1024000 -K true -- -root /usr/local/lib/erlang -progname erl -- -home /root -- -kernel inet_dist_listen_min 40001 -kernel inet_dist_listen_max 40100 -smp disable -name <a href="mailto:gateway@192.168.7.100" target="_blank">gateway@192.168.7.100</a> -setcookie abc -boot start_sasl -config gs_main -pa ../ebin -s gs_main start -extra 192.168.7.100 9001 2<span style="line-height:0px"></span></div></div><div style="line-height:1.5"><br></div><div style="line-height:1.5"><div><b>[root@localhost logs]# strace -c -p 20111</b></div><div>Process 20111 attached - interrupt to quit</div><div>^CProcess 20111 detached<span style="line-height:0px"></span></div></div><div style="line-height:1.5"><br></div><div style="line-height:1.5">strace command has no effect here. And one CPU core keeps running at 100%.</div><div style="line-height:1.5">At the end of the 'gateway' node's log, it says the application is exited:</div><div style="line-height:1.5"><b>[gateway.log]</b></div><div style="line-height:1.5"><div>=INFO REPORT==== 11-Nov-2014::10:21:18 ===</div><div> application: gs_main</div><div> exited: stopped</div><div> type: temporary<span style="line-height:0px"></span></div></div><div style="line-height:1.5"><br></div><div><span style="line-height:1.5">It seems that some endless loop occured after the printing of the =INFO REPORT=.</span></div></div><div><span style="line-height:1.5">The application is not really exited, or the 'ps -ef | grep gateway' command won't find the 20111 process.</span></div><div><br></div><div>Any ideas?</div><div>Thanks in advance.</div><div><br></div><div><div style="color:#909090;font-family:Arial Narrow;font-size:12px">------------------</div><div style="font-size:14px;font-family:Verdana;color:#000"><div>Adam Chan<br></div>
<div></div></div></div><div> </div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div></div>