This isn't acceptable for me, because graceful shutdown can take minutes. Not listening for connections is ok for me because the clients connect to multiple servers and choose whichever seems fastest. This method of handoff reduces the downtime for a given machine to msec. Having a machine down for minutes would still work, but it's not desirable to have rolling deploys take hours instead of minutes. Any solution that requires hot code loading is also not going to work when you upgrade the VM. <div>
<br></div><div>The only way to do better is to be able to pass sockets from one OS process to another (new NIFs), or open a hole to allow the app to modify pf settings. For me, it's sufficient that if a socket is accepted then it'll be handed appropriately and in a timely manner, so I prefer the current (cross-platform and pure erlang) solution. <span></span><br>
<div><br>On Tuesday, May 15, 2012, Loïc Hoguin  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I personally wouldn't want this to become common, because even if you restart immediately, you would lose a few incoming connections (or a lot depending on the popularity of your service). If I understand correctly you go as far as restarting the whole node?<br>

<br>
This isn't like nginx, since nginx doesn't stop listening at any point. You could actually get something closer to nginx by doing this:<br>
<br>
* set acceptors to 0 (incoming connections get queued)<br>
* gracefully shutdown the running connections (application dependent)<br>
* load the new code<br>
* optionally restart parts of your supervision tree<br>
* set acceptors back to N<br>
<br>
You can add an optional set_protocol_options somewhere in there if you need to upgrade the dispatch list (maybe after loading the new code you could always run set_protocol_options(my_<u></u>project:get_dispatch_stuff) or something, which would always get the last options for your project).<br>

<br>
The number of incoming connections queued is also application dependent (and will be upgradable later on so you can increase temporarily).<br>
<br>
This would allow you to do what you want without any extra feature from what is currently planned, and without losing any incoming connections.<br>
<br>
All this is easily scriptable of course.<br>
<br>
If that still doesn't fit your needs I'd suggest opening a ticket to see what others think about it.<br>
<br>
On 05/15/2012 07:35 AM, Bob Ippolito wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The idea is to start a new version of the service and do a quick<br>
hand-off of listening from old to new (possibly even switching back).<br>
This is particularly useful for code upgrades that aren't suitable for<br>
hot code loading. We're doing continuous integration this way, as hot<br>
code loading requires too much work and/or planning for us at this<br>
stage. It's currently an uncommon need but it would be a lot more common<br>
if it was well documented and easier to do.<br>
<br>
As far as load balancers go, we're not using them. For our use case we<br>
don't need them, so why add the complexity and/or cost? There is port<br>
forwarding done by the OS kernel but I want to avoid requiring some<br>
setuid binary to do the privilege escalation that would be necessary to<br>
change ports on the fly.<br>
<br>
Nginx does upgrades in a similar way.<br>
<a href="http://wiki.nginx.org/CommandLine#Upgrading_To_a_New_Binary_On_The_Fly" target="_blank">http://wiki.nginx.org/<u></u>CommandLine#Upgrading_To_a_<u></u>New_Binary_On_The_Fly</a><br>
<br>
On Monday, May 14, 2012, Loïc Hoguin wrote:<br>
<br>
    As with all proposed features I first need to understand what it's<br>
    used for and why, and whether it'll be useful to other people. What<br>
    you are doing just sounds very weird to me and it's the first time I<br>
    hear of a need for something like this so at this point I'm neither<br>
    trying to avoid anything nor considering it useful functionality,<br>
    just wanting to understand why.<br>
<br>
    On 05/15/2012 06:42 AM, Bob Ippolito wrote:<br>
<br>
        Yes, I want the other process to immediately take over.<br>
        Requiring a load<br>
        balancer change isn't an elegant solution, I don't understand<br>
        why you're<br>
        trying to avoid adding this useful functionality.<br>
<br>
        On Monday, May 14, 2012, Loïc Hoguin wrote:<br>
<br>
            You stop listening after you're done gracefully stopping your<br>
            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<br>
        keepalives).<br>
            Gracefully stop your processes.<br>
            Stop the listener.<br>
<br>
            Or do you need another process to take over immediately?<br>
        Because in<br>
            that case you usually don't need to use the same listening<br>
        port, you<br>
            can just change your firewall/lb rules for the port<br>
        redirection from<br>
            80->P1 to 80->P2.<br>
<br>
            On 05/15/2012 03:34 AM, Bob Ippolito wrote:<br>
<br>
                I don't think that is sufficient, you will need to stop<br>
        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<br>
                acceptors<br>
                    to 0. This should be added sometimes this summer<br>
        after the<br>
                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<br>
        application-specific.<br>
                        However,<br>
                        cowboy doesn't currently facilitate any sort of<br>
        graceful<br>
                        shutdown unless<br>
                        you read the source code and poke directly at the<br>
                appropriate<br>
                        supervisors like I did. The application specific<br>
        stuff<br>
                is easily<br>
                        done on<br>
                        your own with a process registry or a timeout,<br>
        we used a<br>
                        combination of<br>
                        gproc and a timeout if things didn't shut down in an<br>
                acceptable<br>
                        time frame.<br>
<br>
                        I would suggest something like<br>
        cowboy:stop_listener/1, maybe<br>
                        something<br>
                        like cowboy:stop_listening/1 or<br>
        cowboy:stop_accepting/1.<br>
<br>
                        On Sun, May 13, 2012 at 11:02 PM, Loïc Hoguin<br>
        <<a>essen@ninenines.eu</a><br>
        <mailto:<a>essen@ninenines.eu</a>>> wrote:<br>
<br>
                            Right, this is pretty much what I said to<br>
        Paul in<br>
                PM. It was in<br>
                            R14B03 that the behavior changed. I<br>
        apparently have<br>
                a @todo<br>
                        wrong<br>
                            past that release, and will take a look if I<br>
        find other<br>
                        things to<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>
        <<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>
        <<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>
        <<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,<br>
        Paweł<br>
                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<br>
        supervisors yesterday<br>
                        (Cowboy seems to<br>
                                        fail to fulfill the promise of<br>
        not killing<br>
                        request processes<br>
                                        after listener removal) and I<br>
        have an<br>
                example.<br>
                        I've only<br>
                                        investigated the case when<br>
        supervisor is<br>
                killed,<br>
                        so YMMV.<br>
                                        Example code is attached. You<br>
        may modify<br>
                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<br>
        answer<br>
                is "no,<br>
                        it does not".<br>
<br>
                                        When supervisor dies, your<br>
        process is<br>
                killed as<br>
                        via link<br>
                                        mechanism, so it may leave some<br>
        unprocessed<br>
                        messages in<br>
                                        inbox. To make sure that every<br>
        delivered<br>
                message<br>
                        is served,<br>
                                        you need to add<br>
        process_flag(trap_exit,<br>
                true).<br>
                        Messages that<br>
                                        are sent after the moment when<br>
                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<br>
        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<br>
        confirmation in the<br>
                        documentation<br>
                                        so was wondering if anyone could<br>
        confirm if<br>
                        messages are<br>
                                        still sent to a supervised gen_svr<br>
                following a<br>
                        shutdown<br>
                                        message?<br>
<br>
                                        If so how do I cleanly shutdown my<br>
                gen_svr without<br>
                                        loosing messages? I read in the<br>
                supervisor child<br>
                        spec<br>
                                        that a shutdown can be set to<br>
        infinity<br>
                which i hoped<br>
                                        would allow me to process the<br>
        msg's in my<br>
                        mailbox but if<br>
                                        I do this will my module<br>
        continue to receive<br>
                        messages<br>
                                        from other processes? Is my approach<br>
                flawed and<br>
                        if so<br>
                                        what other ways are there to cleanly<br>
                shutting<br>
                        down my<br>
                                        gen_svr without loosing messages?<br>
<br>
                                        Many thanks,<br>
<br>
                                        Andy.<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>
        <<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>
        <<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>
        <<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>
                  ______________________________<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>
        <<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>
        <<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>
        <<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>
                  ______________________________<u></u>_________________________<br>
                                        erlang-questions mailing list<br>
        <a>erlang-questions@erlang.org</a><br>
        <mailto:<a>erlang-questions@erlang.org</a>> <javasc</blockquote></blockquote></div></div>