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