Skip to content

Commit

Permalink
Check the future state when setting exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 21, 2024
1 parent a48299b commit 9289cde
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions goodwe/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None:
logger.debug("Response already handled: %s", data.hex())
except RequestRejectedException as ex:
logger.debug("Received exception response: %s", data.hex())
self.response_future.set_exception(ex)
if self.response_future and not self.response_future.done():
self.response_future.set_exception(ex)
self._close_transport()

def error_received(self, exc: Exception) -> None:
Expand Down Expand Up @@ -290,7 +291,8 @@ def data_received(self, data: bytes) -> None:
logger.debug("Response already handled: %s", data.hex())
except RequestRejectedException as ex:
logger.debug("Received exception response: %s", data.hex())
self.response_future.set_exception(ex)
if self.response_future and not self.response_future.done():
self.response_future.set_exception(ex)
# self._close_transport()

def error_received(self, exc: Exception) -> None:
Expand Down

0 comments on commit 9289cde

Please sign in to comment.