Commit Graph

712 Commits (2556a568e7223c5a11c8478cdc966bcdf175b11a)

Author SHA1 Message Date
Tyler Goodlet 2556a568e7 Comment hard-kill-sidestep for now since nursery version covers it? 2021-07-01 19:37:24 -04:00
Tyler Goodlet 6d72a4ef45 Go back to only logging crashes if no pdb gets engaged 2021-07-01 19:37:22 -04:00
Tyler Goodlet f57cc66a7f Solve the root-cancels-child-in-tty-lock race
Finally this makes a cancelled root actor nursery not clobber child
tasks which request and lock the root's tty for the debugger repl.

Using an edge triggered event which is set after all fifo-lock-queued
tasks are complete, we can be sure that no lingering child tasks are
going to get interrupted during pdb use and tty lock acquisition.
Further, even if new tasks do queue up to get the lock, the root will
incrementally send cancel msgs to each sub-actor only once the tty is
not locked by a (set of) child request task(s). Add shielding around all
the critical sections where the child attempts to allocate the lock from
the root such that it won't be disrupted from cancel messages from the
root after the acquire lock transaction has started.
2021-07-01 19:33:43 -04:00
Tyler Goodlet d3e508b7f7 Always shield cancel the caller on cancel-causing-errors, add teardown logging 2021-07-01 19:33:43 -04:00
Tyler Goodlet 8663805042 Distinguish between a local pdb unlock and the tty unlock in root 2021-07-01 19:33:43 -04:00
Tyler Goodlet 9ddb636452 First try: pack cancelled tracebacks and ship to caller 2021-07-01 19:33:41 -04:00
Tyler Goodlet 210dfdf70f Add temp warning msg for context cancel call 2021-07-01 16:25:48 -04:00
Tyler Goodlet 31733b80f0 Add some brief todo notes on idea of shielded breakpoint 2021-07-01 16:25:48 -04:00
Tyler Goodlet 5983c08218 Fix hard kill in debug mode; only do it when debug lock is empty 2021-07-01 16:25:48 -04:00
Tyler Goodlet 93dedefd1f Move some infos to runtime level 2021-07-01 16:25:48 -04:00
Tyler Goodlet 5936e8e2b9 Add PDB level and make runtime below info but above debug 2021-07-01 16:25:48 -04:00
Tyler Goodlet 378c8cee52 Consider relaying context error via raised-in-scope-nursery task 2021-07-01 16:25:46 -04:00
Tyler Goodlet 2f804a977c Move debugger wait inside OCA nursery 2021-07-01 16:24:37 -04:00
Tyler Goodlet 6aa390f714 Don't shield debugger status wait; it causes hangs 2021-07-01 16:24:37 -04:00
Tyler Goodlet 2bcab8b228 Catch and delay errors in the root if debugger is active 2021-07-01 16:24:37 -04:00
Tyler Goodlet dc6fe3137c Don't shield on root cancel it can causes hangs 2021-07-01 16:24:37 -04:00
Tyler Goodlet b02731ca75 Experiment: only disable SIGINT handling in children 2021-07-01 16:24:37 -04:00
Tyler Goodlet e51ba27d01 Don't kill root's immediate children when in debug
If the root calls `trio.Process.kill()` on immediate child proc teardown
when the child is using pdb, we can get stdstreams clobbering that
results in a pdb++ repl where the user can't see what's been typed. Not
killing such children on cancellation / error seems to resolve this
issue whilst still giving reliable termination. For now, code that
special path until a time it becomes a problem for ensuring zombie
reaps.
2021-07-01 16:24:37 -04:00
Tyler Goodlet 9f0fedea14 Add debug example that causes pdb stdin clobbering 2021-07-01 16:24:37 -04:00
Tyler Goodlet e74e93f857 Add a specially handled `ContextCancelled` error 2021-07-01 16:16:26 -04:00
Tyler Goodlet c92fc33b7c Set stream "end of channel" after shielded check!
Another face palm that was causing serious issues for code that is using
the `.shielded` feature..

Add a bunch more detailed comments for all this subtlety and hopefully
get it right once and for all. Also aggregated the `trio` errors that
should trigger closure inside `.aclose()`, hopefully that's right too.
2021-07-01 15:04:58 -04:00
Tyler Goodlet 23dabb9502 Don't clobber msg loop mem chan on rx stream close
Revert this change since it really is poking at internals and doesn't
make a lot of sense. If the context is going to be cancelled then the
msg loop will tear down the feed memory channel when ready, we don't
need to be clobbering it and confusing the runtime machinery lol.
2021-07-01 15:04:58 -04:00
Tyler Goodlet 9469a4b1d8 Modernize streaming tests 2021-07-01 15:04:58 -04:00
Tyler Goodlet e2a556a0f7 Speedup the dynamic pubsub test 2021-07-01 15:04:58 -04:00
Tyler Goodlet 11d471a4cd Add detailed ``@tractor.context`` cancellation/termination tests 2021-07-01 15:04:58 -04:00
Tyler Goodlet b63ccf0007 Drop trailing comma 2021-07-01 15:04:58 -04:00
Tyler Goodlet d896d84b28 Adjustments for non-frozen context dataclass change 2021-07-01 15:04:58 -04:00
Tyler Goodlet fc8d02f963 Wait for debugger lock task context termination 2021-07-01 15:04:58 -04:00
Tyler Goodlet 3b48f89056 Fix exception typing 2021-07-01 15:04:57 -04:00
Tyler Goodlet a146034cb7 Explicitly formalize context/streaming teardown
Add clear teardown semantics for `Context` such that the remote side
cancellation propagation happens only on error or if client code
explicitly requests it (either by exit flag to `Portal.open_context()`
or by manually calling `Context.cancel()`).  Add `Context.result()`
to wait on and capture the final result from a remote context function;
any lingering msg sequence will be consumed/discarded.

Changes in order to make this possible:
- pass the runtime msg loop's feeder receive channel in to the context
  on the calling (portal opening) side such that a final 'return' msg
  can be waited upon using `Context.result()` which delivers the final
  return value from the callee side `@tractor.context` async function.
- always await a final result from the target context function in
  `Portal.open_context()`'s `__aexit__()` if the context has not
  been (requested to be) cancelled by client code on block exit.
- add an internal `Context._cancel_called` for context "cancel
  requested" tracking (much like `trio`'s cancel scope).
- allow flagging a stream as terminated using an internal
  `._eoc` flag which will mark the stream as stopped for iteration.
- drop `StopAsyncIteration` catching in `.receive()`; it does
  nothing.
2021-07-01 15:04:57 -04:00
Tyler Goodlet 0e6f017929 Specially raise a `ContextCancelled` for a task-context rpc 2021-07-01 15:04:56 -04:00
Tyler Goodlet 0d8a5506da Expose streaming components at top level 2021-07-01 15:02:47 -04:00
Tyler Goodlet fed927d00f Add a specially handled `ContextCancelled` error 2021-07-01 15:02:45 -04:00
Tyler Goodlet 1c7c9da99c Add a multi-task streaming test 2021-07-01 15:02:10 -04:00
Tyler Goodlet b6dd58b1cf Avoid mutate on iterate race 2021-07-01 15:02:10 -04:00
Tyler Goodlet 9b70f5d312 Only close recv chan if we get a ref 2021-07-01 15:02:10 -04:00
Tyler Goodlet b92ed701bd Add error case 2021-07-01 15:02:10 -04:00
Tyler Goodlet 4c712a8e47 Support no arg to `Context.started()` like trio 2021-07-01 15:02:10 -04:00
Tyler Goodlet 6bec0ddf0c Fix up var naming and typing 2021-07-01 15:02:10 -04:00
Tyler Goodlet 7192654d51 Only send stop msg if not received from far end 2021-07-01 15:02:10 -04:00
Tyler Goodlet 9d5f193dfd Expose msg stream types at top level 2021-07-01 15:02:10 -04:00
Tyler Goodlet 8b13dc4967 Add dynamic pubsub test using new bidir stream apis 2021-07-01 15:02:10 -04:00
Tyler Goodlet 6f62277c82 Use context for remote debugger locking
A context is the natural fit (vs. a receive stream) for locking the root
proc's tty usage via it's `.started()` sync point. Simplify the
`_breakpoin()` routine to be a simple async func instead of all this
"returning a coroutine" stuff from before we decided that
`tractor.breakpoint()` must be async. Use `runtime` level for locking
logging making it easier to trace.
2021-07-01 15:02:10 -04:00
Tyler Goodlet 207a88e3a8 Be more pedantic with error handling 2021-07-01 15:02:10 -04:00
Tyler Goodlet 2905127dc7 Fix typing 2021-07-01 15:02:10 -04:00
Tyler Goodlet 7d9a551f77 Parametrize with async for style tests 2021-07-01 15:02:10 -04:00
Tyler Goodlet 66d18be2ec Support passing `shield` at stream contruction 2021-07-01 15:02:10 -04:00
Tyler Goodlet bc689427ef Add basic test set 2021-07-01 15:02:10 -04:00
Tyler Goodlet 490cc8ac53 Cancel scope on stream consumer completion 2021-07-01 15:02:10 -04:00
Tyler Goodlet cdafdde092 Expose `@context` decorator at top level 2021-07-01 15:02:10 -04:00