Commit Graph

640 Commits (b254373cd7091e8c0498392f292124ec345e7867)
 

Author SHA1 Message Date
David Wilson b254373cd7 docs: add local task serialization risk 7 years ago
David Wilson 7698f86a9f Whups, don't always enable profiling in mitogen.main() 7 years ago
David Wilson 52d980ad58 issue #155: fork: nop out get_boot_command, it's become quite expensive
-16% reduction in fork cost.
7 years ago
David Wilson e7c98e3bda Have mitogen.main(profiling=True) effect the master process too 7 years ago
David Wilson a868498469 Replace assertions with fixed checks; closes #157. 7 years ago
David Wilson 4dc001f496 parent: fire disconnect upon receiving DEL_ROUTE for context
This lets context.shutdown(wait=True) succeed in the master or any
parent.
7 years ago
David Wilson 862ec21160 core: allow shutdown triggered by any parent, not just immediate parent 7 years ago
David Wilson 0f08783330 core: fix NameError on disconnect 7 years ago
David Wilson 198bec3320 issue #168: ansible: Mitogen must also ignore the extra arguments. 7 years ago
David Wilson 26051caf4c ansible: Pass through connection loader kwargs; closes #168 7 years ago
David Wilson 749eddac71 ansible: fix flake8 errors in helpers.py. 7 years ago
David Wilson 2813d1a968 docs: update 7 years ago
David Wilson 3e384db7c2 service: add basic security policy types. 7 years ago
David Wilson 2ea65420d0 issue #155: fork.py v2, now with full resource cleanup 7 years ago
David Wilson 872181bebd issue #155: core: implement Side._on_fork()
Central mechanism for deleting all non-Latch file descriptors belonging
to the parent process during fork().
7 years ago
David Wilson 80642ed9ec issue #155: core: remove one duplicate set_cloexec(). 7 years ago
David Wilson cb71ce94c4 issue #155: core: be more careful reconfiguring stdio
Many dragons present!
7 years ago
David Wilson 443c94eb39 issue #155: core: prevent set_cloexec() use on standard handles 7 years ago
David Wilson 41ae6623c6 issue #155: parent: generic name generation
Let us override a class attribute to specify prefix from fork.py, rather
than reimplement the same logic.
7 years ago
David Wilson 22cc1a3689 issue #155: core: refactor Latch to avoid TLS use
TLS destructors are not called after fork, therefore we must explicitly
track a global list of free file descriptors, and arrange for that list
to explicitly be destroyed from fork.py.
7 years ago
David Wilson 2cf9edc895 issue #155: core: ensure reused Importer gets new Context reference.
More hacky layering violations.. force Importer's _context attribute to
our new parent.
7 years ago
David Wilson cd5b37ea5b core: Use Side.read() rather than bare os.read(). 7 years ago
David Wilson 1155de85af issue #155: parent: propagate context name too.
This allows context_by_id() in the master to succeed in returning a
Context with a .name matching the context's name, needed for correct
logging.

Previously this would have logged the empty string, because the master
had no mechanism to know the name of a context created by a child.
7 years ago
David Wilson 5579ac936b issue #155: docs: more fork() liability warnings 7 years ago
David Wilson f457f54758 docs: fix formatting 7 years ago
David Wilson d370290687 docs: one more warning 7 years ago
David Wilson 03e08e25fd docs: put huge liability notice in fork() docs. 7 years ago
David Wilson 19d17982f3 core: Split blocking and non-blocking Latch.get()
Mostly just to avoid embarrassing function size, but it may come in
useful for testing later.
7 years ago
David Wilson cba3347556 issue #155: move connection factories to parent.py. 7 years ago
David Wilson 972f77c6b5 parent: have close_nonstandard_fds() ask OS for FD_MAX 7 years ago
David Wilson 721caafb33 core: Do not decrement Latch._waking if we weren't woken. 7 years ago
David Wilson f6c24ab615 issue #155: don't inherit TLS state in mitogen.fork
This is a partial fix to a general problem: deciding which bits of state
to keep from the parent, and which to clear out. When forking from a
heavily threaded process, there will be 2x$n_threads fds just sitting
around doing nothing, due to Latch use in the parent.

We can't just close all nonstandard fds post-fork, since user code may
be expecting some FDs to be preserved.
7 years ago
David Wilson 67e0a4fe59 issue #155: add mitogen.fork to Importer list 7 years ago
David Wilson 48351a1889 issue #155: parent: support Context.shutdown(), reap children on exit.
This permits graceful shutdown of individual contexts, without tearing
down everything.

Update mitogen.parent.Stream to also wait for the child to exit, to
prevent the buildup of zombie processes. This introduces a blocking wait
for process exit on the Broker thread, let's see if we can get away with
it. Chances are reasonable that it'll cause needless hangs on heavily
loaded machines.
7 years ago
David Wilson 6a74edce6b issue #155: parent: move master.Context into parent.
The Context and Router APIs for constructing children and making
function calls should be available in every parent context, as user code
wants to have access to the same API.
7 years ago
David Wilson 447353ecb8 docs: ansible.rst: note multi-host perf isn't great right now 7 years ago
David Wilson f752653e77 core: IoLogger: don't set O_CLOEXEC on standard handles
nested_test was failing due to the recent change to centralize
O_CLOEXEC, since stdout and stderr were being marked as non-inheritable.
That meant child processes would start with no stdout/stderr, triggering
a race between Waker opening its pipes, and IoLogger dup2'ing its pipes
over the stdio handles.

Since the stdio handles were closed, Waker would receive one of them as
one end of its pipe, and consequently have it overwritten by IoLogger.

When IoLogger dups over the top of fd 2, it becomes possible for
Waker.on_read() to be called due to pipe's other end to be closed,
causing an OSError exception with errno EAGAIN to appear.
7 years ago
David Wilson 0eeba2eaa8 core: include fds in Waker repr 7 years ago
David Wilson 7a061fe18b core: merge restart() into io_op()
Any long-running system call may suffer EINTR, so arrange for all IO
calls to be wrapped in the restart loop.
7 years ago
David Wilson 90791768be issue #155: core: slightly rearrange how shutdown works
This eliminates Context.on_disconnect() and instead moves its
functionality to a signal wired up by ExternalContext.main().

It leaves mitogen.master.Context is in a better condition to move into
mitogen.parent where it belongs.
7 years ago
David Wilson 4f93c6823a issue #155: skeletal fork_test. 7 years ago
David Wilson 20780820a6 docs: typo 7 years ago
David Wilson 75b9e1d71e issue #155: docs: document behaviour of forked children 7 years ago
David Wilson 110fdf24cd docs: add mitogen.fork.Stream to internals.rst 7 years ago
David Wilson 1a8ac9f4d1 issue #155: introduce mitogen.fork / Router.fork() 7 years ago
David Wilson db1b5f7d62 issue #155: core: refactor main() to support forking.
* Split setup_globals() from setup_package() and make package setup
  optional (fork never needs it -- synthetic package already exists in
  children and the real package exists in masters).

* Add main() parameter to allow passing in the existing Importer
  instance. In forks from children, this means we inherit all the cached
  module state along with the __loader__ used to import any existing
  modules.
7 years ago
David Wilson 878e7a0902 issue #155: pass reference to existing Router into Stream constructor
This is a hacky layering violation, but it seems the simplest approach
for now: fork needs access to Router, in order to recover the existing
Importer instance.
7 years ago
David Wilson 21ef540cd8 issue #155: parent: split create_socketpair() from create_child() 7 years ago
David Wilson c31a177ebe issue #155: parent: split get_main_kwargs() from get_preamble() 7 years ago
David Wilson b51365209e parent: needless duplicate ADD_ROUTE message
notice_stream() does that already.
7 years ago