This is an archive of the discontinued Mercurial Phabricator instance.

procutil: always waiting on child processes to prevent zombies with 'hg serve'

Authored by rdamazio on May 7 2020, 6:18 AM.



When runbgcommand is invoked by an extension with ensurestart=False, we never
called waitpid - which is fine in most cases, except if that's happening on a
command server (e.g. chg), in which case the child defunct process will just
sit there for as long as the server is running.

The actual semantics of SIGCHLD signal handling is a lot more complex than
it seems, and the POSIX standard *seems* to read that it's ignored by default
and everything would just work without the waitpid if we're not listening for
it, but the truth is that it's only ignored if we *explicitly* set it to
SIG_IGN. We further cannot set it to SIG_IGN or to a catch-all handler across
all of 'hg serve', because Python's suprocess.Popen relies on that signal,
and a few specific parts of hg also set custom handlers, so instead we wait
for specific PIDs in dedicated threads.

I did a poor-man's benchmark of the thread creation and it seems to take
about 1ms, which is way better than the 20+ms from ensurestart=True.

Diff Detail

rHG Mercurial
No Linters Available
No Unit Test Coverage

Event Timeline

rdamazio created this revision.May 7 2020, 6:18 AM
This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.
martinvonz added inline comments.

I'll update the queued commit to not have this change