Finally drop masked `chan.send(None)` related code blocks
parent
38111e8d53
commit
8e83455a78
|
@ -810,61 +810,15 @@ async def process_messages(
|
||||||
log.transport( # type: ignore
|
log.transport( # type: ignore
|
||||||
f'<= IPC msg from peer: {chan.uid}\n\n'
|
f'<= IPC msg from peer: {chan.uid}\n\n'
|
||||||
|
|
||||||
# TODO: conditionally avoid fmting depending
|
# TODO: avoid fmting depending on loglevel for perf?
|
||||||
# on log level (for perf)?
|
# -[ ] specifically `pformat()` sub-call..?
|
||||||
# => specifically `pformat()` sub-call..?
|
# -[ ] use `.msg.pretty_struct` here now instead!
|
||||||
f'{pformat(msg)}\n'
|
f'{pformat(msg)}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
match msg:
|
match msg:
|
||||||
|
# msg for an ongoing IPC ctx session, deliver msg to
|
||||||
# NOTE: this *was a dedicated
|
# local task.
|
||||||
# "graceful-terminate-loop" mechanism using
|
|
||||||
# a `None`-msg-sentinel which would cancel all RPC
|
|
||||||
# tasks parented by this loop's IPC channel; that
|
|
||||||
# is all rpc-scheduled-tasks started over the
|
|
||||||
# connection were explicitly per-task cancelled
|
|
||||||
# normally prior to the `Channel`'s underlying
|
|
||||||
# transport being later closed.
|
|
||||||
#
|
|
||||||
# * all `.send(None)`s were # removed as part of
|
|
||||||
# typed-msging requirements
|
|
||||||
#
|
|
||||||
# TODO: if this mechanism is still desired going
|
|
||||||
# forward it should be implemented as part of the
|
|
||||||
# normal runtime-cancel-RPC endpoints with either,
|
|
||||||
# - a special `msg.types.Msg` to trigger the loop endpoint
|
|
||||||
# (like `None` was used prior) or,
|
|
||||||
# - it should just be accomplished using A
|
|
||||||
# `Start(ns='self', func='cancel_rpc_tasks())`
|
|
||||||
# request instead?
|
|
||||||
#
|
|
||||||
# if msg is None:
|
|
||||||
# case None:
|
|
||||||
# tasks: dict[
|
|
||||||
# tuple[Channel, str],
|
|
||||||
# tuple[Context, Callable, trio.Event]
|
|
||||||
# ] = actor._rpc_tasks.copy()
|
|
||||||
# log.cancel(
|
|
||||||
# f'Peer IPC channel terminated via `None` setinel msg?\n'
|
|
||||||
# f'=> Cancelling all {len(tasks)} local RPC tasks..\n'
|
|
||||||
# f'peer: {chan.uid}\n'
|
|
||||||
# f'|_{chan}\n'
|
|
||||||
# )
|
|
||||||
# # TODO: why aren't we just calling
|
|
||||||
# # `.cancel_rpc_tasks()` with the parent
|
|
||||||
# # chan as input instead?
|
|
||||||
# for (channel, cid) in tasks:
|
|
||||||
# if channel is chan:
|
|
||||||
# await actor._cancel_task(
|
|
||||||
# cid,
|
|
||||||
# channel,
|
|
||||||
# requesting_uid=channel.uid,
|
|
||||||
# ipc_msg=msg,
|
|
||||||
# )
|
|
||||||
# # immediately break out of this loop!
|
|
||||||
# break
|
|
||||||
|
|
||||||
case (
|
case (
|
||||||
StartAck(cid=cid)
|
StartAck(cid=cid)
|
||||||
| Started(cid=cid)
|
| Started(cid=cid)
|
||||||
|
@ -872,7 +826,7 @@ async def process_messages(
|
||||||
| Stop(cid=cid)
|
| Stop(cid=cid)
|
||||||
| Return(cid=cid)
|
| Return(cid=cid)
|
||||||
| CancelAck(cid=cid)
|
| CancelAck(cid=cid)
|
||||||
| Error(cid=cid)
|
| Error(cid=cid) # RPC-task ctx specific
|
||||||
):
|
):
|
||||||
# deliver response to local caller/waiter
|
# deliver response to local caller/waiter
|
||||||
# via its per-remote-context memory channel.
|
# via its per-remote-context memory channel.
|
||||||
|
@ -881,10 +835,8 @@ async def process_messages(
|
||||||
cid,
|
cid,
|
||||||
msg,
|
msg,
|
||||||
)
|
)
|
||||||
# TODO: can remove right?
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# runtime-internal cancellation endpoints
|
# `Actor`(-internal) runtime cancel requests
|
||||||
case Start(
|
case Start(
|
||||||
ns='self',
|
ns='self',
|
||||||
func='cancel',
|
func='cancel',
|
||||||
|
@ -959,11 +911,9 @@ async def process_messages(
|
||||||
)
|
)
|
||||||
|
|
||||||
# the "MAIN" RPC endpoint to schedule-a-`trio.Task`
|
# the "MAIN" RPC endpoint to schedule-a-`trio.Task`
|
||||||
#
|
# ------ - ------
|
||||||
# TODO: impl with native `msgspec.Struct` support !!
|
# -[x] discard un-authed msgs as per,
|
||||||
# -[ ] implement with ``match:`` syntax?
|
# <TODO put issue for typed msging structs>
|
||||||
# -[ ] discard un-authed msgs as per,
|
|
||||||
# <TODO put issue for typed msging structs>
|
|
||||||
case Start(
|
case Start(
|
||||||
cid=cid,
|
cid=cid,
|
||||||
ns=ns,
|
ns=ns,
|
||||||
|
@ -987,7 +937,10 @@ async def process_messages(
|
||||||
# application RPC endpoint
|
# application RPC endpoint
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
func: Callable = actor._get_rpc_func(ns, funcname)
|
func: Callable = actor._get_rpc_func(
|
||||||
|
ns,
|
||||||
|
funcname,
|
||||||
|
)
|
||||||
except (
|
except (
|
||||||
ModuleNotExposed,
|
ModuleNotExposed,
|
||||||
AttributeError,
|
AttributeError,
|
||||||
|
@ -1065,6 +1018,8 @@ async def process_messages(
|
||||||
trio.Event(),
|
trio.Event(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# XXX remote (runtime scoped) error or uknown
|
||||||
|
# msg (type).
|
||||||
case Error() | _:
|
case Error() | _:
|
||||||
# NOTE: this is the non-rpc error case,
|
# NOTE: this is the non-rpc error case,
|
||||||
# that is, an error **not** raised inside
|
# that is, an error **not** raised inside
|
||||||
|
@ -1090,8 +1045,9 @@ async def process_messages(
|
||||||
f'|_{chan}\n'
|
f'|_{chan}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# end of async for, channel disconnect vis
|
# END-OF `async for`:
|
||||||
# ``trio.EndOfChannel``
|
# IPC disconnected via `trio.EndOfChannel`, likely
|
||||||
|
# due to a (graceful) `Channel.aclose()`.
|
||||||
log.runtime(
|
log.runtime(
|
||||||
f'channel for {chan.uid} disconnected, cancelling RPC tasks\n'
|
f'channel for {chan.uid} disconnected, cancelling RPC tasks\n'
|
||||||
f'|_{chan}\n'
|
f'|_{chan}\n'
|
||||||
|
@ -1111,9 +1067,10 @@ async def process_messages(
|
||||||
# connection-reset) is ok since we don't have a teardown
|
# connection-reset) is ok since we don't have a teardown
|
||||||
# handshake for them (yet) and instead we simply bail out of
|
# handshake for them (yet) and instead we simply bail out of
|
||||||
# the message loop and expect the teardown sequence to clean
|
# the message loop and expect the teardown sequence to clean
|
||||||
# up.
|
# up..
|
||||||
# TODO: don't show this msg if it's an emphemeral
|
# TODO: add a teardown handshake? and,
|
||||||
# discovery ep call?
|
# -[ ] don't show this msg if it's an ephemeral discovery ep call?
|
||||||
|
# -[ ] figure out how this will break with other transports?
|
||||||
log.runtime(
|
log.runtime(
|
||||||
f'channel closed abruptly with\n'
|
f'channel closed abruptly with\n'
|
||||||
f'peer: {chan.uid}\n'
|
f'peer: {chan.uid}\n'
|
||||||
|
|
|
@ -393,8 +393,9 @@ class Actor:
|
||||||
|
|
||||||
raise mne
|
raise mne
|
||||||
|
|
||||||
|
# TODO: maybe change to mod-func and rename for implied
|
||||||
|
# multi-transport semantics?
|
||||||
async def _stream_handler(
|
async def _stream_handler(
|
||||||
|
|
||||||
self,
|
self,
|
||||||
stream: trio.SocketStream,
|
stream: trio.SocketStream,
|
||||||
|
|
||||||
|
@ -713,51 +714,6 @@ class Actor:
|
||||||
# TODO: figure out why this breaks tests..
|
# TODO: figure out why this breaks tests..
|
||||||
db_cs.cancel()
|
db_cs.cancel()
|
||||||
|
|
||||||
# XXX TODO XXX: DO WE NEED THIS?
|
|
||||||
# -[ ] is it necessary any more (GC should do it) now
|
|
||||||
# that we have strict(er) graceful cancellation
|
|
||||||
# semantics?
|
|
||||||
# XXX WARNING XXX
|
|
||||||
# Be AWARE OF THE INDENT LEVEL HERE
|
|
||||||
# -> ONLY ENTER THIS BLOCK WHEN ._peers IS
|
|
||||||
# EMPTY!!!!
|
|
||||||
#
|
|
||||||
# if the channel is still connected it may mean the far
|
|
||||||
# end has not closed and we may have gotten here due to
|
|
||||||
# an error and so we should at least try to terminate
|
|
||||||
# the channel from this end gracefully.
|
|
||||||
#if (
|
|
||||||
# not self._peers
|
|
||||||
# and chan.connected()
|
|
||||||
#):
|
|
||||||
# log.runtime(
|
|
||||||
# 'Terminating channel with `None` setinel msg\n'
|
|
||||||
# f'|_{chan}\n'
|
|
||||||
# )
|
|
||||||
# try:
|
|
||||||
# # ORIGINALLY we sent a msg loop terminate
|
|
||||||
# # sentinel (`None`) which triggers
|
|
||||||
# # cancellation of all remotely started
|
|
||||||
# # tasks.
|
|
||||||
# #
|
|
||||||
# # HOWEVER, after we added typed msging,
|
|
||||||
# # you can't just willy nilly send `None`
|
|
||||||
# # wherever since it might be invalid given
|
|
||||||
# # the currently configured msg-spec.
|
|
||||||
# #
|
|
||||||
# # SO, this was all removed and I'm pretty
|
|
||||||
# # confident we don't need it replaced with
|
|
||||||
# # a manual RPC to
|
|
||||||
# # a `Actor.cancel_rpc_tasks()` right?
|
|
||||||
# await chan.send(None)
|
|
||||||
|
|
||||||
# # XXX: do we want this? NO RIGHT?
|
|
||||||
# # causes "[104] connection reset by peer" on other end
|
|
||||||
# # await chan.aclose()
|
|
||||||
|
|
||||||
# except trio.BrokenResourceError:
|
|
||||||
# log.runtime(f"Channel {chan.uid} was already closed")
|
|
||||||
|
|
||||||
# TODO: rename to `._deliver_payload()` since this handles
|
# TODO: rename to `._deliver_payload()` since this handles
|
||||||
# more then just `result` msgs now obvi XD
|
# more then just `result` msgs now obvi XD
|
||||||
async def _push_result(
|
async def _push_result(
|
||||||
|
|
Loading…
Reference in New Issue