Skip to content

Commit

Permalink
handle bad socket state on initial send
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramblurr committed Sep 10, 2023
1 parent 5a050e7 commit 24a2a4d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rpc/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import Any, Dict, Optional, TypeVar

import zmq
from zmq.error import ZMQError

from .util import current_time_us, unique_id, ErrorHandlerFn
from .error import TimeoutException
Expand Down Expand Up @@ -84,18 +85,25 @@ def dispatch(
def _poll_data(data: Any) -> None:
"""Implements lazy-pirate poll (see zmq guide chapter 4)"""
assert self.socket
self.socket.send(data)
failed_initial_send = False
try:
self.socket.send(data)
except ZMQError:
logging.debug("failed initial send, socket in bad state")
failed_initial_send = True
retries_left = _retries
while retries_left > 0:
if self.socket.poll(_timeout):
break
if not failed_initial_send:
if self.socket.poll(_timeout):
break
retries_left -= 1
logging.info(
f"response from server timed out retries_left={retries_left}"
)
self.close()
self._ensure_connected()
self.socket.send(data)
failed_initial_send = False

if retries_left == 0:
self.close()
Expand Down

0 comments on commit 24a2a4d

Please sign in to comment.