Skip to content

Commit

Permalink
Introduce asyncio.wait_for to websocket recv
Browse files Browse the repository at this point in the history
Believe it or not, it was possible for this script to wait to receive
something from the validator for eternity and this is not a good
prroperty in a cron job. `wait_for` will exit after 10 seconds so
that we can move onto the next message. It is hoped 10 is generous
enough, and sufficient enough to generate enough logging to identify
any issues we might otherwise be seeing between validator and
collector nodes.
  • Loading branch information
ross-spencer committed Jul 5, 2024
1 parent 92bbd92 commit c2da7fa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/collector_node/collector_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,17 @@ async def send_to_ws(validator_websocket, data_to_send: dict):
)
data_to_send = await sign_message(json.dumps(data_to_send))
await validator_websocket.send(data_to_send)
msg = await validator_websocket.recv()
logger.info("websocket response: %s", msg)
try:
# `wait_for` exits early if necessary to avoid the validator
# swallowing this message without return so we can continue onto the next.
msg = await asyncio.wait_for(validator_websocket.recv(), 10)
if "ERROR" in msg:
logger.error("websocket response: %s (%s)", msg, feed)
return
logger.error("websocket response: %s (%s)", msg, feed)
except asyncio.exceptions.TimeoutError:
logger.error("websocket wait_for resp timeout for feed '%s'", feed)
return


async def fetch_and_send(identity: dict) -> None:
Expand Down

0 comments on commit c2da7fa

Please sign in to comment.