Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context oriented error relay and MsgStream overruns #261

Merged
merged 31 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f4793af
Error on mal-use of `Context.started()`
goodboy Nov 5, 2021
568902a
Add test for #265: "msg sent before stream opened"
goodboy Nov 28, 2021
3f6099f
Add a double started error checking test
goodboy Dec 3, 2021
c5c3f7e
Use `tractor.Context` throughout the runtime core
goodboy Dec 3, 2021
872b24a
Prove we've fixed #265
goodboy Dec 3, 2021
d307eab
Rework `Actor.send_cmd()` to `.start_remote_task()`
goodboy Dec 3, 2021
6751349
Add a stream overrun exception
goodboy Dec 5, 2021
92b540d
Add internal msg stream backpressure controls
goodboy Dec 6, 2021
2680a94
Always set `Context._portal` on the caller task side
goodboy Dec 6, 2021
185dbc7
Disable msg stream backpressure by default
goodboy Dec 6, 2021
2b05ffc
Add context stream overrun tests
goodboy Dec 6, 2021
7b9d410
Adjust remaining examples and tests for non-backpressure default
goodboy Dec 6, 2021
41a3e6a
Type check fixes
goodboy Dec 6, 2021
f3432bd
Enable bp on clustering test
goodboy Dec 6, 2021
4ea5c9b
Pop context on `.open_context()` exit
goodboy Dec 6, 2021
b826ec8
Better idea, enable backpressure on opened streams
goodboy Dec 6, 2021
318027e
Raise stream overruns on one side never opened
goodboy Dec 6, 2021
142083d
Don't cancel the context on overrun cases
goodboy Dec 6, 2021
58805a0
Slight delay to avoid flaky bcast race
goodboy Dec 6, 2021
1f8e1cc
Only pop contexts on decorated entrypoints
goodboy Dec 6, 2021
c9132de
Move maybe-raise-error-msg logic into context
goodboy Dec 6, 2021
a79cdc7
Make cancel case expect multi-error
goodboy Dec 6, 2021
4b40599
Fix ignore warning log message
goodboy Dec 6, 2021
63ecae7
Add a basic no-errors-when-backpressure stream test
goodboy Dec 6, 2021
52a2b7a
Bump windows timeout again
goodboy Dec 6, 2021
fd6f457
Rename test mod
goodboy Dec 6, 2021
efba522
Move context-streaming operational tests into one mod
goodboy Dec 6, 2021
4856285
Add back broken send chan ignore block
goodboy Dec 6, 2021
df59071
Bleh cast to list for `msgpack`
goodboy Dec 6, 2021
703dee8
Add stream open before started, detailed semantics comment
goodboy Dec 7, 2021
faaecbf
Add nooz
goodboy Dec 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/full_fledged_streaming_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def stream_data(seed):
for i in range(seed):
yield i
await trio.sleep(0) # trigger scheduler
await trio.sleep(0.0001) # trigger scheduler


# this is the third actor; the aggregator
Expand Down
37 changes: 37 additions & 0 deletions newsfragments/261.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Add cross-actor-task ``Context`` oriented error relay, a new
stream overrun error-signal ``StreamOverrun``, and support
disabling ``MsgStream`` backpressure as the default before a stream
is opened or by choice of the user.

We added stricter semantics around ``tractor.Context.open_stream():``
particularly to do with streams which are only opened at one end.
Previously, if only one end opened a stream there was no way for that
sender to know if msgs are being received until first, the feeder mem
chan on the receiver side hit a backpressure state and then that
condition delayed its msg loop processing task to eventually create
backpressure on the associated IPC transport. This is non-ideal in the
case where the receiver side never opened a stream by mistake since it
results in silent block of the sender and no adherence to the underlying
mem chan buffer size settings (which is still unsolved btw).

To solve this we add non-backpressure style message pushing inside
``Actor._push_result()`` by default and only use the backpressure
``trio.MemorySendChannel.send()`` call **iff** the local end of the
context has entered ``Context.open_stream():``. This way if the stream
was never opened but the mem chan is overrun, we relay back to the
sender a (new exception) ``SteamOverrun`` error which is raised in the
sender's scope with a special error message about the stream never
having been opened. Further, this behaviour (non-backpressure style
where senders can expect an error on overruns) can now be enabled with
``.open_stream(backpressure=False)`` and the underlying mem chan size
can be specified with a kwarg ``msg_buffer_size: int``.

Further bug fixes and enhancements in this changeset include:
- fix a race we were ignoring where if the callee task opened a context
it could enter ``Context.open_stream()`` before calling
``.started()``.
- Disallow calling ``Context.started()`` more then once.
- Enable ``Context`` linked tasks error relaying via the new
``Context._maybe_raise_from_remote_msg()`` which (for now) uses
a simple ``trio.Nursery.start_soon()`` to raise the error via closure
in the local scope.
Loading