Guard receive-path transport rendering
Skip raw packet, decoded message, peer, and channel formatting when transport logging is disabled. Keep message processing and wire reads outside the guards so logging controls never affect IPC flow. Also narrow the remaining pretty-struct TODO to require a non-raising formatter with native-repr fallback. (this patch was generated in some part by `opencode` using `gpt-5.6-sol` (`openai`))wkt/start_or_cancel_tests_474
parent
84ec895150
commit
935c8cf656
|
|
@ -309,7 +309,10 @@ class MsgpackTransport(MsgTransport):
|
||||||
log.transport(f'received header {size}') # type: ignore
|
log.transport(f'received header {size}') # type: ignore
|
||||||
msg_bytes: bytes = await self.recv_stream.receive_exactly(size)
|
msg_bytes: bytes = await self.recv_stream.receive_exactly(size)
|
||||||
|
|
||||||
log.transport(f"received {msg_bytes}") # type: ignore
|
if log.at_least_level('transport'):
|
||||||
|
log.transport( # type: ignore
|
||||||
|
f'received {msg_bytes}'
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
# NOTE: lookup the `trio.Task.context`'s var for
|
# NOTE: lookup the `trio.Task.context`'s var for
|
||||||
# the current `MsgCodec`.
|
# the current `MsgCodec`.
|
||||||
|
|
|
||||||
|
|
@ -1003,20 +1003,18 @@ async def process_messages(
|
||||||
task_status.started(loop_cs)
|
task_status.started(loop_cs)
|
||||||
|
|
||||||
async for msg in chan:
|
async for msg in chan:
|
||||||
log.transport( # type: ignore
|
if log.at_least_level('transport'):
|
||||||
f'IPC msg from peer\n'
|
log.transport( # type: ignore
|
||||||
f'<= {chan.aid.reprol()}\n\n'
|
f'IPC msg from peer\n'
|
||||||
|
f'<= {chan.aid.reprol()}\n\n'
|
||||||
|
|
||||||
# TODO: use of the pprinting of structs is
|
# TODO: pretty-printing structs is FRAGILE;
|
||||||
# FRAGILE and should prolly not be
|
# -[ ] add a non-raising log formatter with
|
||||||
#
|
# native-repr fallback before using
|
||||||
# avoid fmting depending on loglevel for perf?
|
# `.msg.pretty_struct` here.
|
||||||
# -[ ] specifically `pretty_struct.pformat()` sub-call..?
|
# f'{pretty_struct.pformat(msg)}\n'
|
||||||
# - how to only log-level-aware actually call this?
|
f'{msg}\n'
|
||||||
# -[ ] use `.msg.pretty_struct` here now instead!
|
)
|
||||||
# f'{pretty_struct.pformat(msg)}\n'
|
|
||||||
f'{msg}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
match msg:
|
match msg:
|
||||||
# msg for an ongoing IPC ctx session, deliver msg to
|
# msg for an ongoing IPC ctx session, deliver msg to
|
||||||
|
|
@ -1262,11 +1260,12 @@ async def process_messages(
|
||||||
log.exception(message)
|
log.exception(message)
|
||||||
raise RuntimeError(message)
|
raise RuntimeError(message)
|
||||||
|
|
||||||
log.transport(
|
if log.at_least_level('transport'):
|
||||||
'Waiting on next IPC msg from\n'
|
log.transport(
|
||||||
f'peer: {chan.aid.reprol()}\n'
|
'Waiting on next IPC msg from\n'
|
||||||
f'|_{chan}\n'
|
f'peer: {chan.aid.reprol()}\n'
|
||||||
)
|
f'|_{chan}\n'
|
||||||
|
)
|
||||||
|
|
||||||
# END-OF `async for`:
|
# END-OF `async for`:
|
||||||
# IPC disconnected via `trio.EndOfChannel`, likely
|
# IPC disconnected via `trio.EndOfChannel`, likely
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue