Yes, I want the other process to immediately take over. Requiring a load balancer change isn't an elegant solution, I don't understand why you're trying to avoid adding this useful functionality.<span></span><br>
<br>On Monday, May 14, 2012, Loïc Hoguin  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You stop listening after you're done gracefully stopping your currently running processes.<br>

<br>
For HTTP that could be something like:<br>
<br>
Set acceptors to 0.<br>
Optionally set 'onrequest' hook to reply with a 503 (for keepalives).<br>
Gracefully stop your processes.<br>
Stop the listener.<br>
<br>
Or do you need another process to take over immediately? Because in that case you usually don't need to use the same listening port, you can just change your firewall/lb rules for the port redirection from 80->P1 to 80->P2.<br>

<br>
On 05/15/2012 03:34 AM, Bob Ippolito wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I don't think that is sufficient, you will need to stop listening as<br>
well so the next OS process can take over.<br>
<br>
On Monday, May 14, 2012, Loïc Hoguin wrote:<br>
<br>
 Â  Â This will be possible later on by reducing the number of acceptors<br>
 Â  Â to 0. This should be added sometimes this summer after the acceptor<br>
 Â  Â split happens in Cowboy.<br>
<br>
 Â  Â On 05/14/2012 07:26 PM, Bob Ippolito wrote:<br>
<br>
 Â  Â  Â  Â I agree that graceful shutdown is very application-specific.<br>
 Â  Â  Â  Â However,<br>
 Â  Â  Â  Â cowboy doesn't currently facilitate any sort of graceful<br>
 Â  Â  Â  Â shutdown unless<br>
 Â  Â  Â  Â you read the source code and poke directly at the appropriate<br>
 Â  Â  Â  Â supervisors like I did. The application specific stuff is easily<br>
 Â  Â  Â  Â done on<br>
 Â  Â  Â  Â your own with a process registry or a timeout, we used a<br>
 Â  Â  Â  Â combination of<br>
 Â  Â  Â  Â gproc and a timeout if things didn't shut down in an acceptable<br>
 Â  Â  Â  Â time frame.<br>
<br>
 Â  Â  Â  Â I would suggest something like cowboy:stop_listener/1, maybe<br>
 Â  Â  Â  Â something<br>
 Â  Â  Â  Â like cowboy:stop_listening/1 or cowboy:stop_accepting/1.<br>
<br>
 Â  Â  Â  Â On Sun, May 13, 2012 at 11:02 PM, Loïc Hoguin <<a>essen@ninenines.eu</a><br>
 Â  Â  Â  Â <mailto:<a>essen@ninenines.eu</a>>> wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â Right, this is pretty much what I said to Paul in PM. It was in<br>
 Â  Â  Â  Â  Â  Â R14B03 that the behavior changed. I apparently have a @todo<br>
 Â  Â  Â  Â wrong<br>
 Â  Â  Â  Â  Â  Â past that release, and will take a look if I find other<br>
 Â  Â  Â  Â things to<br>
 Â  Â  Â  Â  Â  Â fix in the docs.<br>
<br>
 Â  Â  Â  Â  Â  Â Copy pasting my private reply on this:<br>
<br>
 Â  Â  Â  Â  Â  Â Ultimately if we remove the listener I think we want to stop<br>
 Â  Â  Â  Â everything.<br>
<br>
 Â  Â  Â  Â  Â  Â For "server is overloaded" situations, you can very well use the<br>
 Â  Â  Â  Â 'onrequest' hook which can be set or changed dynamically through<br>
 Â  Â  Â  Â  Â  Â cowboy:set_protocol_options, in addition to giving it in<br>
 Â  Â  Â  Â  Â  Â start_listener. Takes a fun that has a single arg as a Req,<br>
 Â  Â  Â  Â returns<br>
 Â  Â  Â  Â  Â  Â a Req, and if you replied from within it it doesn't dispatch the<br>
 Â  Â  Â  Â  Â  Â request and stops there (you can also force close the<br>
 Â  Â  Â  Â connection by<br>
 Â  Â  Â  Â  Â  Â setting the Connection header to "close").<br>
<br>
 Â  Â  Â  Â  Â  Â And adding this:<br>
<br>
 Â  Â  Â  Â  Â  Â For graceful shutdowns, well it's highly application<br>
 Â  Â  Â  Â dependent. Some<br>
 Â  Â  Â  Â  Â  Â apps are just short lived connections, so not accepting requests<br>
 Â  Â  Â  Â  Â  Â plus a short delay ought to do it. Some are long lived, which<br>
 Â  Â  Â  Â  Â  Â probably requires to send a shutdown message. Some apps may have<br>
 Â  Â  Â  Â  Â  Â connections critical enough that you don't want to shutdown<br>
 Â  Â  Â  Â them.<br>
 Â  Â  Â  Â  Â  Â It's up to the application implementor to devise the<br>
 Â  Â  Â  Â strategy to use<br>
 Â  Â  Â  Â  Â  Â for stopping.<br>
<br>
<br>
 Â  Â  Â  Â  Â  Â On 05/14/2012 02:34 AM, Fred Hebert wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â This is just a guess, but is it possible that this is<br>
 Â  Â  Â  Â due to the<br>
 Â  Â  Â  Â  Â  Â  Â  Â fact<br>
 Â  Â  Â  Â  Â  Â  Â  Â Cowboy is using simple_one_for_one supervision? In Pre<br>
 Â  Â  Â  Â R15, if I<br>
 Â  Â  Â  Â  Â  Â  Â  Â recall<br>
 Â  Â  Â  Â  Â  Â  Â  Â correctly, the shutdown of sofo supervisors was<br>
 Â  Â  Â  Â asynchronous. The<br>
 Â  Â  Â  Â  Â  Â  Â  Â supervisor would just die and let its children figure<br>
 Â  Â  Â  Â out it was<br>
 Â  Â  Â  Â  Â  Â  Â  Â gone.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â Starting with R15, things started being synchronous and the<br>
 Â  Â  Â  Â  Â  Â  Â  Â supervisor<br>
 Â  Â  Â  Â  Â  Â  Â  Â would wait. A brutal kill that made things work fine<br>
 Â  Â  Â  Â before R15<br>
 Â  Â  Â  Â  Â  Â  Â  Â (excluding the issue of the application master killing<br>
 Â  Â  Â  Â  Â  Â  Â  Â everything) could<br>
 Â  Â  Â  Â  Â  Â  Â  Â start breaking in later versions.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â Again, this is just a guess, without looking at the<br>
 Â  Â  Â  Â source or<br>
 Â  Â  Â  Â  Â  Â  Â  Â anything.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â On Sun May 13 14:12:18 2012, Bob Ippolito wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Yes, it is documented that request processes<br>
 Â  Â  Â  Â continue after<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â you stop<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â the listener. This is incorrect.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â On Sunday, May 13, 2012, Anthony Ramine wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â PaweÅ‚, from what I gather your supervisor waits 1 ms<br>
 Â  Â  Â  Â before<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â killing its children; I think it's pretty normal<br>
 Â  Â  Â  Â that some<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â messages are left unprocessed.<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Bob, cowboy_requests_sup' shutdown strategy is<br>
 Â  Â  Â  Â brutal_kill,<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â is it<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â documented somewhere that Cowboy waits before<br>
 Â  Â  Â  Â killing requests'<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â processes?<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Regards,<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â --<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Anthony Ramine<br>
<br>
<br>
<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Le 10 mai 2012 Ã  22:37, Bob Ippolito a Ã©crit :<br>

 Â  Â  Â  Â <a href="https://gist.github.com/____2655724" target="_blank">https://gist.github.com/____<u></u>2655724</a><br>
 Â  Â  Â  Â <<a href="https://gist.github.com/__2655724" target="_blank">https://gist.github.com/__<u></u>2655724</a>><br>
 Â  Â  Â  Â <<a href="https://gist.github.com/__2655724" target="_blank">https://gist.github.com/__<u></u>2655724</a><br>
 Â  Â  Â  Â <<a href="https://gist.github.com/2655724" target="_blank">https://gist.github.com/<u></u>2655724</a>>><br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â On Thu, May 10, 2012 at 2:53 AM, PaweÅ‚ Peregud<br>
 Â  Â  Â  Â <<a>paulperegud@gmail.com</a> <mailto:<a>paulperegud@gmail.com</a>><br>
 Â  Â  Â  Â <javascript:_e({}, 'cvml',<br>
 Â  Â  Â  Â '<a>paulperegud@gmail.com</a><br>
 Â  Â  Â  Â <mailto:<a>paulperegud@gmail.com</a>>');>> wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â I was having fun with supervisors yesterday<br>
 Â  Â  Â  Â (Cowboy seems to<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â fail to fulfill the promise of not killing<br>
 Â  Â  Â  Â request processes<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â after listener removal) and I have an example.<br>
 Â  Â  Â  Â I've only<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â investigated the case when supervisor is killed,<br>
 Â  Â  Â  Â so YMMV.<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Example code is attached. You may modify it to<br>
 Â  Â  Â  Â check the<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â behavior in your case.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Start supervisor tree with<br>
 Â  Â  Â  Â exp_sup_sup:start_link(). Execute<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â test with exp_sup_sup:test() and<br>
 Â  Â  Â  Â exp_sup_sup:test_simple().<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â In case of dying supervisor the answer is "no,<br>
 Â  Â  Â  Â it does not".<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â When supervisor dies, your process is killed as<br>
 Â  Â  Â  Â via link<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â mechanism, so it may leave some unprocessed<br>
 Â  Â  Â  Â messages in<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â inbox. To make sure that every delivered message<br>
 Â  Â  Â  Â is served,<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â you need to add process_flag(trap_exit, true).<br>
 Â  Â  Â  Â Messages that<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â are sent after the moment when supervisor dies<br>
 Â  Â  Â  Â are not<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â processed.<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Best regards,<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Paul.<br>
<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â On May 9, 2012 11:06 AM, "Andy Richards"<br>
 Â  Â  Â  Â <andy.richards.iit@googlemail.<u></u>____com<br>
 Â  Â  Â  Â <mailto:<a>andy.richards.iit@googlemail.com</a>><br>
 Â  Â  Â  Â <javascript:_e({}, 'cvml',<br>
 Â  Â  Â  Â 'andy.richards.iit@googlemail.<u></u>____com<br>
 Â  Â  Â  Â <mailto:<a>andy.richards.iit@googlemail.com</a>>');>> wrote:<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Hi,<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â I can't seem to see any confirmation in the<br>
 Â  Â  Â  Â documentation<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â so was wondering if anyone could confirm if<br>
 Â  Â  Â  Â messages are<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â still sent to a supervised gen_svr following a<br>
 Â  Â  Â  Â shutdown<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â message?<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â If so how do I cleanly shutdown my gen_svr without<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â loosing messages? I read in the supervisor child<br>
 Â  Â  Â  Â spec<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â that a shutdown can be set to infinity which i hoped<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â would allow me to process the msg's in my<br>
 Â  Â  Â  Â mailbox but if<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â I do this will my module continue to receive<br>
 Â  Â  Â  Â messages<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â from other processes? Is my approach flawed and<br>
 Â  Â  Â  Â if so<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â what other ways are there to cleanly shutting<br>
 Â  Â  Â  Â down my<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â gen_svr without loosing messages?<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Many thanks,<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Andy.<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ______________________________<u></u>_____________________<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â erlang-questions mailing list<br>
 Â  Â  Â  Â <a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>> <javascript:_e({},<br>
 Â  Â  Â  Â 'cvml',<br>
 Â  Â  Â  Â '<a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>>')__;><br>
 Â  Â  Â  Â <a href="http://erlang.org/mailman/____listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/____<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a>><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a>>><br>
<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ______________________________<u></u>_____________________<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â erlang-questions mailing list<br>
 Â  Â  Â  Â <a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>> <javascript:_e({},<br>
 Â  Â  Â  Â 'cvml',<br>
 Â  Â  Â  Â '<a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>>')__;><br>
 Â  Â  Â  Â <a href="http://erlang.org/mailman/____listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/____<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a>><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a>>><br>
<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ______________________________<u></u>_____________________<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â erlang-questions mailing list<br>
 Â  Â  Â  Â <a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>> <javascript:_e({},<br>
 Â  Â  Â  Â 'cvml',<br>
 Â  Â  Â  Â '<a>erlang-questions@erlang.org</a><br>
 Â  Â  Â  Â <mailto:<a>erlang-questions@erlang.org</a>>')__;><br>
 Â  Â  Â  Â <a href="http://erlang.org/mailman/____listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/____<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a>><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a>>><br>
<br>
<br>
<br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â ______________________________<u></u>_____________________<br>
 Â  Â  Â  Â  Â  Â  Â  Â  Â  Â erlang-questions mailing list<br>
 Â  Â  Â  Â <a>erlang-questions@erlang.org</a> <mailto:<a>erlang-questions@erlang.org</a>><br>
 Â  Â  Â  Â <a href="http://erlang.org/mailman/____listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/____<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a>><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a>>><br>
<br>
 Â  Â  Â  Â  Â  Â  Â  Â ______________________________<u></u>_____________________<br>
 Â  Â  Â  Â  Â  Â  Â  Â erlang-questions mailing list<br>
 Â  Â  Â  Â <a>erlang-questions@erlang.org</a> <mailto:<a>erlang-questions@erlang.org</a>><br>
 Â  Â  Â  Â <a href="http://erlang.org/mailman/____listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/____<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a>><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/__listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/__<u></u>listinfo/erlang-questions</a><br>
 Â  Â  Â  Â <<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a>>><br>
<br>
<br>
<br>
 Â  Â  Â  Â  Â  Â --<br>
 Â  Â  Â  Â  Â  Â Loïc Hoguin<br>
 Â  Â  Â  Â  Â  Â Erlang Cowboy<br>
 Â  Â  Â  Â  Â  Â Nine Nines<br>
<br>
<br>
<br>
<br>
 Â  Â --<br>
 Â  Â Loïc Hoguin<br>
 Â  Â Erlang Cowboy<br>
 Â  Â Nine Nines<br>
<br>
</blockquote>
<br>
<br>
-- <br>
Loïc Hoguin<br>
Erlang Cowboy<br>
Nine Nines<br>
</blockquote>