-
Notifications
You must be signed in to change notification settings - Fork 12
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
Avoid inf recursion in BroadcastReceiver.receive()
#343
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goodboy
added
bug
Something isn't working
api
streaming
cancellation
SC teardown semantics and anti-zombie semantics
trionics
labels
Nov 15, 2022
goodboy
changed the title
Breceiver internals rework
Avoid inf recursion in Nov 15, 2022
BroadcastReceiver.receive()
2 tasks
goodboy
force-pushed
the
breceiver_internals
branch
3 times, most recently
from
December 13, 2022 20:21
1de4cce
to
38b6b00
Compare
This was referenced Jan 10, 2023
goodboy
force-pushed
the
breceiver_internals
branch
from
January 26, 2023 21:05
3d926d2
to
565057b
Compare
goodboy
changed the base branch from
piker_pin
to
ipc_failure_while_streaming
January 26, 2023 21:28
goodboy
force-pushed
the
breceiver_internals
branch
4 times, most recently
from
January 29, 2023 01:07
770de3b
to
e631d67
Compare
goodboy
force-pushed
the
ipc_failure_while_streaming
branch
from
January 29, 2023 19:55
710dee0
to
13c9ead
Compare
goodboy
force-pushed
the
breceiver_internals
branch
from
January 29, 2023 20:02
ed24111
to
dd44d77
Compare
Driven by a bug found in `piker` where we'd get an inf recursion error due to `BroadcastReceiver.receive()` being called when consumer tasks are awoken but no value is ready to `.nowait_receive()`. This new rework takes an approach closer to the interface and internals of `trio.MemoryReceiveChannel` particularly in terms of, - implementing a `BroadcastReceiver.receive_nowait()` and using it within the async `.receive()`. - failing over to an internal `._receive_from_underlying()` when the `_nowait()` call raises `trio.WouldBlock`. - adding `BroadcastState.statistics()` for debugging and testing dropping recursion from `.receive()`.
Since one-way streaming can be accomplished by just *not* sending on one side (and/or thus wrapping such usage in a more restrictive API), we just drop the recv-only parent type. The only method different was `MsgStream.send()`, now merged in. Further in usage of `.subscribe()` we monkey patch the underlying stream's `.send()` onto the delivered broadcast receiver so that subscriber tasks can two-way stream as though using the stream directly. This allows us to more definitively drop `tractor.open_stream_from()` in the longer run if we so choose as well; note currently this will potentially create an issue if a caller tries to `.send()` on such a one way stream.
Makes the broadcast test suite not hang xD, and is our expected default behaviour. Also removes a ton of commented legacy cruft from before the refactor to remove the `.receive()` recursion and fixes some typing. Oh right, and in the case where there's only one subscriber left we warn log about it since in theory we could actually entirely unwind the bcaster back to the original underlying, though not sure if that's sane or works for some use cases (like wanting to have some other subscriber get added dynamically later).
goodboy
force-pushed
the
breceiver_internals
branch
from
January 29, 2023 20:04
dd44d77
to
4ce2dcd
Compare
guilledk
approved these changes
Jan 30, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
api
bug
Something isn't working
cancellation
SC teardown semantics and anti-zombie semantics
streaming
trionics
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Originally driven by a bug found in
piker
where we'd get an inf recursion error due toBroadcastReceiver.receive()
being recursively called when consumer tasks are awoken but no value is ready tonowait
receive.trio.MemoryReceiveChannel
particularly in terms of,BroadcastReceiver.receive_nowait()
and using it within the async.receive()
._receive_from_underlying()
when the_nowait()
call raisestrio.WouldBlock
BroadcastState.statistics()
for debugging and testing.receive()
BroadcastReceiver._raise_on_lag: bool
which can be set to avoidLagged
errors from being raised in the case where a user knows they want/need a cheap or nasty patternMsgStream
as only stream type!MsgStream
andReceiveMsgStream
merging the two types into the former; the only thing differing was.send()
which should really be a choice not to use since (at least eventually) the underlying impl will always be a bidir stream.BroadcastReciever
delivered fromMsgStream.subscribe()
with a.send()
which delegates to the underlying stream making it very simple to support multi-task usage of any fan-out stream 🏄🏼TODO:
ipython
WIP commit (aac8d34) from this historyhopefully a (set of) test(s) to demonstrate the original recursion error?=> don't think it's worth it, if it shows up again then yes..