From 6631fad79091a1d77791f4d152c019d05e3872c0 2015-02-13 00:21:36 From: Min RK Date: 2015-02-13 00:21:36 Subject: [PATCH] handle message arriving when sockets are closed check both the incoming and outgoing streams before proceeding to send messages --- diff --git a/IPython/html/base/zmqhandlers.py b/IPython/html/base/zmqhandlers.py index 4ddcb5e..f1159e8 100644 --- a/IPython/html/base/zmqhandlers.py +++ b/IPython/html/base/zmqhandlers.py @@ -106,12 +106,11 @@ class ZMQStreamHandler(WebSocketHandler): # we can close the connection more gracefully. self.stream.close() - + def check_origin(self, origin): """Check Origin == Host or Access-Control-Allow-Origin. Tornado >= 4 calls this method automatically, raising 403 if it returns False. - We call it explicitly in `open` on Tornado < 4. """ if self.allow_origin == '*': return True @@ -173,7 +172,10 @@ class ZMQStreamHandler(WebSocketHandler): def _on_zmq_reply(self, stream, msg_list): # Sometimes this gets triggered when the on_close method is scheduled in the # eventloop but hasn't been called. - if stream.closed(): return + if self.stream.closed() or stream.closed(): + self.log.warn("zmq message arrived on closed channel") + self.close() + return channel = getattr(stream, 'channel', None) try: msg = self._reserialize_reply(msg_list, channel=channel)