Skip to content

Commit

Permalink
consistently use error if we're disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed Aug 29, 2023
1 parent 1095879 commit d9ebf0c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions txtorcon/torcontrolprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,14 @@ def connectionMade(self):
def connectionLost(self, reason):
"Protocol API"
txtorlog.msg('connection terminated: ' + str(reason))
if reason.check(ConnectionDone):
self._when_disconnected.fire(self)
else:
self._when_disconnected.fire(reason)
self._when_disconnected.fire(
Failure(
TorDisconnectError(
text="Tor connection terminated",
error=reason,
)
)
)

# ...and this is why we don't do on_disconnect = Deferred() :(
# and instead should have had on_disconnect() method that
Expand All @@ -711,8 +715,10 @@ def connectionLost(self, reason):
else:
self.on_disconnect.errback(reason)
self.on_disconnect = None
self._when_disconnected.fire(self)

outstanding = [self.command] + self.commands if self.command else self.commands
self.command = None
self.defer = None
for d, cmd, cmd_arg in outstanding:
if not d.called:
d.errback(
Expand Down

0 comments on commit d9ebf0c

Please sign in to comment.