Skip to content

Commit ea0291b

Browse files
committed
Check if the stream is closed before writing final websocket close packet.
Closes tornadoweb#390.
1 parent eee9953 commit ea0291b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tornado/websocket.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ def close(self):
387387
"""Closes the WebSocket connection."""
388388
if self.client_terminated and self._waiting:
389389
tornado.ioloop.IOLoop.instance().remove_timeout(self._waiting)
390+
self._waiting = None
390391
self.stream.close()
391-
else:
392+
elif not self.stream.closed():
392393
self.stream.write("\xff\x00")
393394
self._waiting = tornado.ioloop.IOLoop.instance().add_timeout(
394395
time.time() + 5, self._abort)
@@ -603,6 +604,7 @@ def _handle_message(self, opcode, data):
603604

604605
def close(self):
605606
"""Closes the WebSocket connection."""
607+
if self.stream.closed(): return
606608
self._write_frame(True, 0x8, b(""))
607609
self._started_closing_handshake = True
608610
self._waiting = tornado.ioloop.IOLoop.instance().add_timeout(time.time() + 5, self._abort)

0 commit comments

Comments
 (0)