##// END OF EJS Templates
Check time of last ping before timing out a missing pong.
Richard Everson -
Show More
@@ -109,6 +109,7 b' WS_PING_INTERVAL = 30000'
109
109
110 class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):
110 class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):
111 ping_callback = None
111 ping_callback = None
112 last_ping = 0
112 last_pong = 0
113 last_pong = 0
113
114
114 @property
115 @property
@@ -151,7 +152,8 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
151
152
152 # start the pinging
153 # start the pinging
153 if self.ping_interval > 0:
154 if self.ping_interval > 0:
154 self.last_pong = ioloop.IOLoop.instance().time()
155 self.last_ping = ioloop.IOLoop.instance().time() # Remember time of last ping
156 self.last_pong = self.last_ping
155 self.ping_callback = ioloop.PeriodicCallback(self.send_ping, self.ping_interval)
157 self.ping_callback = ioloop.PeriodicCallback(self.send_ping, self.ping_interval)
156 self.ping_callback.start()
158 self.ping_callback.start()
157
159
@@ -161,15 +163,19 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
161 self.ping_callback.stop()
163 self.ping_callback.stop()
162 return
164 return
163
165
164 # check for timeout on pong
166 # check for timeout on pong. Make sure that we really have sent a recent ping in
165 since_last_pong = 1e3 * (ioloop.IOLoop.instance().time() - self.last_pong)
167 # case the machine with both server and client has been suspended since the last ping.
166 if since_last_pong > self.ping_timeout:
168 now = ioloop.IOLoop.instance().time()
169 since_last_pong = 1e3 * (now - self.last_pong)
170 since_last_ping = 1e3 * (now - self.last_ping)
171 if since_last_ping < 2*self.ping_interval and since_last_pong > self.ping_timeout:
167 self.log.warn("WebSocket ping timeout after %i ms.", since_last_pong)
172 self.log.warn("WebSocket ping timeout after %i ms.", since_last_pong)
168 self.close()
173 self.close()
169 return
174 return
170
175
171 self.ping(b'')
176 self.ping(b'')
172
177 self.last_ping = now
178
173 def on_pong(self, data):
179 def on_pong(self, data):
174 self.last_pong = ioloop.IOLoop.instance().time()
180 self.last_pong = ioloop.IOLoop.instance().time()
175
181
General Comments 0
You need to be logged in to leave comments. Login now