[PATCH stateful-chg] commandserver: move _socket state to handler

Yuya Nishihara yuya at tcha.org
Fri May 19 12:01:41 EDT 2017


On Thu, 18 May 2017 09:42:44 -0700, Jun Wu wrote:
> Excerpts from Yuya Nishihara's message of 2017-05-18 22:59:37 +0900:
> > Can you give some pointers to understand how getsocket() will be used in chg?
> 
>   # service.mainloop
>   while not shouldexit:
>     sock = handler.getsocket()
>   # handler.getsocket
>   - handler reads IPC, may fork to preload in background
>     - the non-forked handler returns the old sock
>     - the forked handler does the following:
>       - preload
>       - atomic replace socket (so the old process will exit)
>       - return socket (so service starts to use the new one)

I recalled that, thanks. Can we move the fork logic to commandserver.py?

  # unixforkingservice
  mainloop:
    if h.need_to_reinitialize_in_background?  # reads IPC
      fork
      if child:
        reinitialize_server
      else:
        keep serving in the current process

  reinitialize_server:
    close_existing_socket
    h.preload
    h.rebind_socket(new_socket)

IMHO, it isn't easy to abstract fork() stuff cleanly. Doing that in service
subclass or handler would make it harder to track where resources are created
and released, and could lead to subtle bugs.


More information about the Mercurial-devel mailing list