diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index 49b399d97d..fccddaf085 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -132,9 +132,9 @@ class TrezorClient: self.session_counter += 1 def close(self): - if self.session_counter == 1: + self.session_counter = max(self.session_counter - 1, 0) + if self.session_counter == 0: self.transport.end_session() - self.session_counter -= 1 def cancel(self): self._raw_write(messages.Cancel()) diff --git a/python/src/trezorlib/transport/protocol.py b/python/src/trezorlib/transport/protocol.py index 8bee47374d..92afcfb3db 100644 --- a/python/src/trezorlib/transport/protocol.py +++ b/python/src/trezorlib/transport/protocol.py @@ -93,9 +93,9 @@ class Protocol: self.session_counter += 1 def end_session(self) -> None: - if self.session_counter == 1: + self.session_counter = max(self.session_counter - 1, 0) + if self.session_counter == 0: self.handle.close() - self.session_counter -= 1 def read(self) -> protobuf.MessageType: raise NotImplementedError