From 24a2a4d5944a12bbd8440eeee24ec352e84176fe Mon Sep 17 00:00:00 2001 From: Casey Link Date: Sun, 10 Sep 2023 20:03:04 +0200 Subject: [PATCH] handle bad socket state on initial send --- rpc/client_sync.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rpc/client_sync.py b/rpc/client_sync.py index ec52adc..f2d8d05 100644 --- a/rpc/client_sync.py +++ b/rpc/client_sync.py @@ -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 @@ -84,11 +85,17 @@ 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}" @@ -96,6 +103,7 @@ def _poll_data(data: Any) -> None: self.close() self._ensure_connected() self.socket.send(data) + failed_initial_send = False if retries_left == 0: self.close()