remove listener on close too

This was failing to clean up after WrongPassword disconnects.
This commit is contained in:
Brian Warner 2016-06-24 18:57:49 -07:00
parent 6a2cbf9014
commit cfcd74db4b
2 changed files with 8 additions and 0 deletions

View File

@ -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)

View File

@ -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)