Tolerate one decode error; may have been a registry ping

optional_msgspec_support
Tyler Goodlet 2021-09-30 11:32:28 -04:00
parent ef75883b62
commit 135459ca25
1 changed files with 8 additions and 6 deletions

View File

@ -177,17 +177,19 @@ class MsgspecTCPStream(MsgpackTCPStream):
log.transport(f"received {msg_bytes}") # type: ignore log.transport(f"received {msg_bytes}") # type: ignore
try: try:
assert not last_decode_failed
yield self.decode(msg_bytes) yield self.decode(msg_bytes)
except ( except (
msgspec.DecodingError, msgspec.DecodingError,
UnicodeDecodeError, UnicodeDecodeError,
): ):
# ignore decoding errors for now and assume they have to if not last_decode_failed:
# do with a channel drop - hope that receiving from the # ignore decoding errors for now and assume they have to
# channel will raise an expected error and bubble up. # do with a channel drop - hope that receiving from the
log.error('`msgspec` failed to decode!?') # channel will raise an expected error and bubble up.
last_decode_failed = True log.error('`msgspec` failed to decode!?')
last_decode_failed = True
else:
raise
async def send(self, data: Any) -> None: async def send(self, data: Any) -> None:
async with self._send_lock: async with self._send_lock: