From 5916cba69fc1f8a25fe8e749e3c4427897b3d228 Mon Sep 17 00:00:00 2001 From: Vladimir Magamedov Date: Thu, 18 Apr 2024 19:13:08 +0300 Subject: [PATCH] Don't attempt to write into transport if it is closing due to connection error. Fixes #180 and #185. --- grpclib/protocol.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grpclib/protocol.py b/grpclib/protocol.py index 314449c..66f66c1 100644 --- a/grpclib/protocol.py +++ b/grpclib/protocol.py @@ -476,6 +476,8 @@ def __terminated__(self, reason: str) -> None: @property def closable(self) -> bool: + if self._transport.is_closing(): + return False if self._h2_connection.state_machine.state is ConnectionState.CLOSED: return False stream = self._h2_connection.streams.get(self.id)