Commit Graph

1045 Commits (master)

Author SHA1 Message Date
David Wilson a35fcf44cc ansible: restructure to avoid intermediate imports 6 years ago
David Wilson 75a78c9ff4 ansible: connection plugin v2
Now featuring one roundtrip per module invocation.
6 years ago
David Wilson f3e51a7b18 core: CALL_FUNCTION should check auth_id, not src_id 6 years ago
David Wilson f001eba23e ansible: Merge module runner into helpers.py. 6 years ago
David Wilson 67d4c13ffa Remove old TCP draft. 6 years ago
David Wilson 32f6ee7d43 issue #40: mitogen.unix initial implementation. 6 years ago
David Wilson 37e3151be8 fakessh: restore unpickle() semantics. 6 years ago
David Wilson e63e9d299e docs: add Message documentation 6 years ago
David Wilson 10230f62dd core: Message.reply() helper function 6 years ago
David Wilson 6fc8fa5b22 core: Don't crash if a stream is missing a side. 6 years ago
David Wilson 9238e09ae8 core: Restore behaviour of unpickling Router-specific Context subclass 6 years ago
David Wilson dd088908df select: clean up API. 6 years ago
David Wilson df07e47d24 core: de-munge Message.unpickle() vs. Receiver.get(). 6 years ago
David Wilson a39cd44bf2 core: add auth_id field. 6 years ago
David Wilson a54c96faae core: remove unused SecurityError. 6 years ago
David Wilson 07d4d799f1 Add mitogen.main() decorator mainly for docs and demo use. 6 years ago
David Wilson 55c23e1c57 issue #68: replace sets with lists
Fix a MyPy warning by only passing lists to select.select(). At least on
Python 2.x, select.select() was internally converting the sets to lists
anyway.

By the time lists become inefficient here, it is likely that
select.select() itself will also be inefficient, and need replaced with
.poll() or similar.

No discernible performance different when transferring django.db.models
to a local VM.
6 years ago
David Wilson 09eb3fd9ba utils: support log_to_file(usec=True) 6 years ago
David Wilson 2848d35aff importer: warn on duplicate request, simplify preload logic
* Children should never generate a request for a module that has already
  been sent, however there are a variety of edge cases where, e.g.
  asynchronous calls are made into unloaded modules in a set of
  children, causing those children to request modules (and deps) in a
  different order, which might break deduplication. So add a warning to
  catch when this happens, so we can figure out how to handle it.
  Meanwhile it's only a warning since in the worst case, this just adds
  needless latency.

* Don't bother treating sent packages separately, there doesn't seem to
  be any need for this (after docs are updated to match how preloading
  actually works now).
6 years ago
David Wilson 2e729e54cc importer: fix glaring bug in find_related()
Overwriting 'fullname' variable caused basically nonsensical filtering.
Result was including the module being searched in the list of
dependencies, which was causing ModuleResponder to send it early, which
was causing contexts to start importing the module before preloading of
dependencies had completed.
6 years ago
David Wilson 0dbb1ec028 importer: warn once about missing source and cache negative hit 6 years ago
David Wilson a0d9d34231 core: fix profiling
* SIGTERM safety net prevents profiler from writing results, so disable
  it when profiling is active.
* fix warning corrupting stream when profiling=True
6 years ago
David Wilson b158259c86 Split up parent and master modules
Knocks 4kb off network footprint for a proxy connection.
6 years ago
David Wilson 5f2fa2cda6 importer: always refuse builtins and __builtin__. 6 years ago
David Wilson 0f899f34ff importer: new format to signal ImportError
Previously we'd send just None in GET_MODULE reply, but now since there
is no single request-reply structure, we must include the fullname in
the LOAD_MODULE response and make all of its data fields None to
indicate the same.
6 years ago
David Wilson 07ae14f11d importer: semi-functional preloader
Doesn't yet implement the rules in the docs, but I think the doc rules
could maybe change to match this. Needs lots of cleanup work and
thorough testing, but this is a great start.
6 years ago
David Wilson 4d01dc3ba6 Initial pass at module preloading
* Don't implement the rules for when preloading occurs yet
* Don't attempt to streamily preload modules downstream while this
  context hasn't yet received the final module. There is quite
  significant latency buried in here, but for now it's a lot of work to
  fix.

This works well enough to handle at least the mitogen package, but it's
likely broken for anything bigger.
6 years ago
David Wilson b75e77b410 master: force set_block() in tty_create_child too.
For gevent, just as in 5f7633cd56
6 years ago
David Wilson ed71ae72f8 master: make mitogen minimally functional under gevent
It seems gevent automatically sets blocking behaviour on fds produced by
the socket module, which causes the Python process we fork to fail
horribly. So in the child, always reset the blocking flag.
6 years ago
David Wilson 247f50e08d master: add comment 6 years ago
David Wilson bbcfc585a8 master: add a comment to explain what's going on, and fix log msg.
Closes #70
6 years ago
David Wilson 3cbe9baf6d issue #70: remove redundant 'raise SystemExit'
Either execvp succeeds, in which case the process image is replaced, or
execvp throws an exception, in which case control flow exits the frame
anyway.
6 years ago
David Wilson 326886832e Add license text everywhere. 6 years ago
David Wilson f1f36cec35 Simplify the API, make Broker optional and auto-shutdown on main thread exit. 6 years ago
David Wilson bbcf1a0bd4 Fix confusing return statements, closes #67. 6 years ago
Alex Willmer 3831ac360f Replace all calls to file() with open()
Although these are synonyms in Python 2.x, when using MyPy to typecheck
code use of file() causes spurious errors.

This commit also serves as one small step to Python 3.x compatibility,
since 3.x removes the file() builtin.
6 years ago
David Wilson c09dcd82a7 Fix Python 3 fix :/ closes #57 6 years ago
Alex Willmer 77d57a7e38 fakessh: Remove colon causing SyntaxError
fixes #58
6 years ago
David Wilson 658806bde8 fakessh: interruptible wait compatible with <2.7; closes #55 6 years ago
David Wilson b3491b190c master: Lazy-format more logging arguments, minor 3.x compat increments 6 years ago
Alex Willmer 0e7cc55e33 first stage: Remove/dedent else block
Since the above if block ends in a call to os.execv() this block will
only ever run when the if condition was false. Hence putting it in an
else clause is unnecessary.
6 years ago
Alex Willmer d1c10f64a5 first stage: Use string concatenation 6 years ago
Alex Willmer b490cde604 first stage: eliminate whitespace 6 years ago
Alex Willmer c7c0266e99 first stage: single letter variables 6 years ago
David Wilson 3d0e8c36d2 issue #49: 2.x/3.x compatible decode.
Much uglier command line, but it works across major Python releases.
6 years ago
David Wilson db9bec8720 Implement Alex's awesome idea of zlibbing the first stage too! Closes #49 6 years ago
David Wilson 0481c08beb Ensure _run_defer() fully executes at least once before shutdown
Without this, it's possible for Waker to be start_received() after the
shutdown signal has already been sent, resulting in 5 second delay
during shutdown.

Additionally mask EBADF during os.write() to waker's write side.
Necessary since nothing synchronizes writer threads from the broker
thread during shutdown. Could be done with a lock instead, but this is
cheaper.
6 years ago
David Wilson 828f60351b importer: Delete _get_module_via_parent entirely
Can't figure out what it's supposed to do any more, and can't find a
version of Ansible before August 2016 (when I wrote that code) that
seems to need it.

Add some more mitigations to avoid sending dylibs.
6 years ago
David Wilson b1ad04330b docs: move Router.route() into Sphinx. 6 years ago
David Wilson fb759f7c16 docs: move Broker docstrings into Sphinx. 6 years ago
David Wilson ffa063cc01 docs: annother barriage of cross-reference fixes. 6 years ago
David Wilson 7f3a58d514 core: Remove unused on_shutdown attribute. 6 years ago
David Wilson c9daa2ff30 docs: move fakessh docs into Sphinx. 6 years ago
David Wilson 6a10ab605e docs: move mitogen.utils docs to Sphinx. 6 years ago
David Wilson ec66152e37 docs: better io_op doc, move Side docs to Sphinx. 6 years ago
David Wilson 0767abf26f docs: move BasicStream docs into Sphinx. 6 years ago
David Wilson b7a9aa46cf core: More robust shutdown
Now there is a separate SHUTDOWN message that relies only on being
received by the broker thread, the main thread can be hung horribly and
the process will still eventually receive a SIGTERM.
6 years ago
David Wilson 3285fc2f75 Implement test_aborted_on_local_context_disconnect 6 years ago
David Wilson 690ee6dbe2 Fix select_test failure, remove crap old timing_test. 6 years ago
David Wilson 15bf0f54e2 Beginnings of module_finder_test 6 years ago
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 6 years ago
David Wilson 9b13a4cc61 Fix 2 call_function_test failures. 6 years ago
David Wilson 79dd00db5a master: hack to avoid executing __main__. 6 years ago
David Wilson 6f5d4882da We don't support sets, so don't use them in module loader(!) 6 years ago
David Wilson ecd39e4f2a add missing IOLOG, fixes _iter_read/SshTest. 6 years ago
David Wilson 451fb347d0 master: include related modules in ModuleResponder response 6 years ago
David Wilson 4af920094a iter_read: also treat 0-byte read as disconnection 6 years ago
David Wilson d169b55d64 select: fix typo 6 years ago
David Wilson af6812b458 Fix context naming for sudo and via=. 6 years ago
David Wilson f1d82c7284 More API documentation. 6 years ago
David Wilson b7f95e558f Better document Router API and constructors. 6 years ago
David Wilson 815f23bddd Sense of block= parameter was inverted. 6 years ago
David Wilson c4d9f124c6 Document Sender and Receiver classes. 6 years ago
David Wilson 849ccebe04 receiver: only permit one notify callback
There is no point spamming a list for every function call, there is no
use case where multiple notify callbacks would be useful.
6 years ago
David Wilson 1be10575a1 importer: Don't respond to non-.py[co] imports. 6 years ago
David Wilson 48bf987570 issue #20: fix queue.get() parameter list. 6 years ago
David Wilson f869e088f8 issue #20: tests and fixes for mitogen.master.Select(). 6 years ago
David Wilson e3d967ebeb issue #20: initial implementation of mitogen.master.Select(). 6 years ago
David Wilson 14783c75e8 issue #9: log warning when a cross-sibling CALL_FUNCTION occurs
First step to making it a fatal error.
6 years ago
David Wilson 9de1fca3bf issue #9: ensure messages arrive on the expected stream
If no ADD_ROUTE message has been received from the master associating a
stream with a particular context ID, then it is expected messages
originating from that context ID can only be routed via the parent.
6 years ago
David Wilson 4de321a3b0 Adjust get_boot_command to match _first_stage change
inspect module includes the staticmethod decorator added by
a8d1dc6730
6 years ago
David Wilson c810f66bcc issue #19: whoops, implement sliding window properly 6 years ago
David Wilson 43ccbf0459 issue #19: second attempt at import scanner
This version is based on the modulefinder standard library module,
pruned back just to handle modules we know have been loaded already, and
to scan module-level imports only, rather than imports occurring in
class and function scope (crappy heuristic, but assume they are lazy
imports).

The ast and compiler modules were far too slow, whereas this version can
bytecode compile and scan all the imports for django.db.models (58
modules) in around 200ms.. 3.4ms per dependency, it's probably not going
to get much faster than that.
6 years ago
David Wilson 175abee2c9 Fix inverted logic. 6 years ago
David Wilson 8054fa867a Only import compiler when necessary, it's not available in 3.x. 6 years ago
Alex Willmer aa817f1b83 Handle failure to import the ast module 6 years ago
Alex Willmer dd8271f061 Fix stale references to m.master.connect & m.ssh.connect
I'm fairly sure these updates are correct, but I'm not able to run the
test suite to confirm.
6 years ago
Alex Willmer d706b7d6b8 Update lingering references to with_broker & run_with_broker
A previous commit renamed run_with_broker() and with_broker() to
run_with_router() and with_router() respctively. Some references were
missed.
6 years ago
Alex Willmer dc26460a28 Add missing LOG import
Fixes an undefined variable error found by pylint
6 years ago
Alex Willmer 3b24314a8b Use fully qualified Context
Fixes an undefined variable error found by pylint
6 years ago
Alex Willmer 57a0aa26bf Add missing import of AnsibleError
Found with pylint
6 years ago
Alex Willmer f2ea38a963 Add missing auth_incorrect_msg used to in exception message
Found using pylint
6 years ago
Alex Willmer 1f955fc655 Declare self-less method as static
Found using pylint
6 years ago
Alex Willmer 36754254b2 Add missing imports: ast, compiler
Found using pylint
6 years ago
David Wilson 01729b18a5 core: use an output deque rather than string to improve worst case perf
This probably worsens performance in the common case, but it prevents
runaway producers (see e.g. issue #36) from spending all their CPU
copying around huge strings.

It's also a small step towards a solution to issue #6, which will
replace the output buffer with some sort of fancier queue anyway.

This reduces a particular 40 second run of rsync to 1.5 seconds.
6 years ago
David Wilson eb060e1a0e Document Router.profiling. 6 years ago
David Wilson effe4117e1 Treat EPIPE as disconnect too; needed for fakessh. 6 years ago
David Wilson 9c4bf37cfc Remove final vestiges of context.key. 6 years ago
David Wilson 05cc74d142 core: Support profiling 6 years ago
David Wilson b827ee1bc7 Delete mitogen.utils.log_to_tmp() 6 years ago
David Wilson 400c971f4a fakessh: SSH server uses user's shell to parse command line. 6 years ago
David Wilson 04ea5306e9 Document a bunch of mitogen.master and move more docstrings into Sphinx. 6 years ago
David Wilson b2f13f1fa4 master: propagate routes for IDs allocated via ALLOCATE_ID
needed for inter-child rsync.
6 years ago
David Wilson 750e9fab24 Make log_to_file accept string level rather than logging package constant
Saves an import, pain in the ass to type all the time.
6 years ago
David Wilson a9387b0504 core: remove pointless eval() of ARGV0 environment variable. 6 years ago
David Wilson 1411790f56 master: make write_all() handle O_NONBLOCK and deadlines. 6 years ago
David Wilson 2ee7309378 master: send_await() always unpickles now. 6 years ago
David Wilson 769ece2514 fakessh: improve logging slightly.
Makes it easier to match up reads/writes across log files by using
message byte count
6 years ago
David Wilson fb9ce1054c core: set O_NONBLOCK on every side. Closes #33
The last time I tested set_nonblock() as a fix for the rsync hang, I
used F_SETFD rather than F_SETFL, which resulted in no error, but also
did not set O_NONBLOCK. Turns out missing O_NONBLOCK was the problem.

The rsync hang was due to every context blocking in os.write() waiting
for either a parent or child buffer to empty, which was exacerbated by
rsync's own pipelining, that allows writes from both sides to proceed
even while reads aren't progressing. The hang was due to os.write() on a
blocking fd blocking until buffer space is available to complete the
write. Partial writes are only supported when O_NONBLOCK is enabled.
6 years ago
David Wilson db225638f0 core: Make iter_read() handle deadline (and non-blocking IO) properly 6 years ago
David Wilson 7a60b20dc6 core: Generalize/duplicate the call/send_await code using Receiver. 6 years ago
David Wilson 76d35df889 master: use decorators rather than call_with_deadline(with_context=..) 6 years ago
David Wilson 76d1e66790 fakessh: use decorators rather than call_with_deadline(with_context=..) 6 years ago
David Wilson e4c832685d core: synchronize Stream._output_buf by deferring send()
Previously _output_buf was racy. This may or may not be cheaper than
simply using a lock, but it requires much less code, so I prefer it for
now.
6 years ago
David Wilson ead67de883 core: make Side.write() return None rather than crash if side already closed. 6 years ago
David Wilson 74b31bbe47 core: better Message.__repr__. 6 years ago
David Wilson 2a365aa9b0 Replace `with_context` parameter with mitogen.core.takes_econtext decorator 6 years ago
David Wilson 8d4005c264 fakessh: fix non-master context ID allocation. 6 years ago
David Wilson bd8001d481 fakessh: Fix NameError. 6 years ago
David Wilson e7c70127bf fakessh: return child exit status 6 years ago
David Wilson 77b8d28c68 fakessh: Use local process's sys.executable. 6 years ago
David Wilson 175fe7a4e1 fakessh: IoPump() doesn't need Process reference. 6 years ago
David Wilson 8dad396e27 Make subsystem requests die with a useful error. 6 years ago
David Wilson 4244a4609c Reduce CHUNK_SIZE to paper over a hang with rsync 6 years ago
David Wilson c67119501b Keep allocate_id() in the enhanced router class. 6 years ago
David Wilson 02a37d2339 Fix format string. 6 years ago
David Wilson 4720eb1c55 core: add ALLOCATE_ID message for fakessh. 6 years ago
David Wilson e796487cca core: allow sending 0-byte messages. 6 years ago
David Wilson 78d5575d4e Fix proxy connection: pickling changes broke it. 6 years ago
David Wilson b809d43865 Move more docstrings out of core.py. 6 years ago
David Wilson 918edf5145 Add TODO 6 years ago
David Wilson 502266f115 Fix Channel constructor and add simple test; closes #32 6 years ago
David Wilson 4f50707b82 core: support takes_econtext and takes_router decorators. 6 years ago
David Wilson 76e476dcfa Tidy up logging of command lines for easier cutpaste. 6 years ago
David Wilson e66590f098 Initial version of ModuleFinder, but it's slooooow. 6 years ago
David Wilson 53467d394d Log forwarded events just as the docs suggest they're logged. 6 years ago
David Wilson dc446f9042 ssh: Learn to type passwords and supply pubkeys.
Now ssh requires a tty allocation. This presents a scalability problem,
a future version could selectively allocate a tty only if typing
passwords is desired.

Sudo's tty handling is now moved into mitogen.master.
6 years ago
David Wilson 38a9482860 Add hacks to allow Mock to be imported. 6 years ago
David Wilson 1f99dcb435 fix unbelievably dumb variable shadowing 6 years ago
David Wilson 4e8b9ecb27 ssh: Support disabling strict host key checking. 6 years ago
David Wilson 559b88ff12 ssh: Support specifying the port too. 6 years ago
David Wilson be9e55fe8c pickle: support Context(), use same unpickler everywhere.
* Support passing Context() objects in function calls and return values.
  Now the fakessh demo from the documentation index would work
  correctly.

* Since slaves can communicate with each other now, they should also use
  the same approach to unpickling as the master already used. Collapse
  away all the unpickle extension crap and hard-wire just the 3 types
  that support unpickling.
6 years ago
David Wilson 11acc031a9 pickle: Prevent access to the _Dead and CallError constructors
This should be pretty much identical the same behaviour as before, but
the extra assertion makes me feel happier.
6 years ago
David Wilson e75f1d8579 Add call_function_test, fix various exception bugs. 6 years ago
David Wilson e7ff6259a3 Initial commit. 6 years ago