Boost logo

Boost Users :

From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2020-04-21 16:59:19


On Tue, Apr 21, 2020 at 2:40 PM Martijn Otto via Boost-users <
boost-users_at_[hidden]> wrote:

> The easiest way is to simply replace the old process with the new,
> improved version after stopping the listener for the old process.
>
> The io_context is kept alive by handlers registered. Initially, this is
> probably only the acceptor listening for incoming connections. Then, as
> connections are established, handlers are registered for those too.
> When you want to replace the process, you cancel the acceptor, so only
> the existing connections keep the io_context alive.
>
> At this point, the listener is closed and the port is free to use by
> the new process. When all connections in the old process terminate, the
> process then stops (because no more handlers are registered).
>

That's interesting, and simple. I guess I could extend one of my HTTP route,
or my existing WebSocket protocol handling, to have the new server
communicate
with the old one, notifying him to drop the listener, and stop listening on
the main
port, so that the io_context naturally can go out of scope, and the process
terminate.
With possibly a grace period for existing clients to disconnect normally,
before forceful termination.

> There is a small timeframe during which requests might fail, because
> the old process stops listening and the new process is not yet
> accepting connections. Depending on your platform, there are ways
> around this (e.g. SO_REUSEPORT on linux).
>

You mean because the main server port would not be released right away
when the older server stops the io_context's TCP acceptor? Preventing the
new server to start listening on that port right away? --DD



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net