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

Handle TransportConnectionError when receiving #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
33 changes: 18 additions & 15 deletions compute_horde/compute_horde/miner_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,24 @@ def deferred_send_model(self, model: BaseRequest):
self.deferred_send_tasks.append(task)

async def read_messages(self):
async for msg in self.transport:
try:
msg = self.accepted_request_type().parse(msg)
except ValidationError as ex:
error_msg = f"Malformed message from miner {self.miner_name}: {str(ex)}"
logger.info(error_msg)
self.deferred_send_model(self.build_outgoing_generic_error(error_msg))
continue

try:
await self.handle_message(msg)
except UnsupportedMessageReceived:
error_msg = f"Unsupported message from miner {self.miner_name}"
logger.exception(error_msg)
self.deferred_send_model(self.build_outgoing_generic_error(error_msg))
try:
async for msg in self.transport:
try:
msg = self.accepted_request_type().parse(msg)
except ValidationError as ex:
error_msg = f"Malformed message from miner {self.miner_name}: {str(ex)}"
logger.info(error_msg)
self.deferred_send_model(self.build_outgoing_generic_error(error_msg))
continue
try:
await self.handle_message(msg)
except UnsupportedMessageReceived:
error_msg = f"Unsupported message from miner {self.miner_name}"
logger.exception(error_msg)
self.deferred_send_model(self.build_outgoing_generic_error(error_msg))
except TransportConnectionError as exc:
logger.warning("%s connection error when trying to receive: %r", self.miner_name, exc)
self.deferred_send_model(self.build_outgoing_generic_error(error_msg))


class UnsupportedMessageReceived(Exception):
Expand Down
Loading