From cfcd74db4bc1f5309e2fba1d5bb4fd210b62c4cd Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 24 Jun 2016 18:57:49 -0700 Subject: [PATCH] remove listener on close too This was failing to clean up after WrongPassword disconnects. --- src/wormhole/server/rendezvous.py | 4 ++++ src/wormhole/server/rendezvous_websocket.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/wormhole/server/rendezvous.py b/src/wormhole/server/rendezvous.py index 54c1b1a..a62cc82 100644 --- a/src/wormhole/server/rendezvous.py +++ b/src/wormhole/server/rendezvous.py @@ -68,11 +68,15 @@ class Mailbox: return messages def add_listener(self, handle, send_f, stop_f): + #log.msg("add_listener", self._mailbox_id, handle) self._listeners[handle] = (send_f, stop_f) + #log.msg(" added", len(self._listeners)) return self.get_messages() def remove_listener(self, handle): + #log.msg("remove_listener", self._mailbox_id, handle) self._listeners.pop(handle, None) + #log.msg(" removed", len(self._listeners)) def has_listeners(self): return bool(self._listeners) diff --git a/src/wormhole/server/rendezvous_websocket.py b/src/wormhole/server/rendezvous_websocket.py index 69e7567..a6289a7 100644 --- a/src/wormhole/server/rendezvous_websocket.py +++ b/src/wormhole/server/rendezvous_websocket.py @@ -224,6 +224,9 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): def handle_close(self, msg, server_rx): if not self._mailbox: raise Error("must open mailbox before closing") + if self._listening: + self._mailbox.remove_listener(self) + self._listening = False self._mailbox.close(self._side, msg.get("mood"), server_rx) self._mailbox = None self.send("closed") @@ -235,6 +238,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): self.sendMessage(payload, False) def onClose(self, wasClean, code, reason): + #log.msg("onClose", self, self._mailbox, self._listening) if self._mailbox and self._listening: self._mailbox.remove_listener(self)