From 51f5ad28d5c3a17bfad7d9b55555b23223eff43b Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 3 Jun 2019 11:45:01 +0100 Subject: [PATCH] correctly handle rejected websocket connections in Tornado (Fixes #114) --- engineio/async_drivers/tornado.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engineio/async_drivers/tornado.py b/engineio/async_drivers/tornado.py index 59ff1bfb..aa6d1002 100644 --- a/engineio/async_drivers/tornado.py +++ b/engineio/async_drivers/tornado.py @@ -135,7 +135,12 @@ def make_response(status, headers, payload, environ): mode. """ tornado_handler = environ['tornado.handler'] - tornado_handler.set_status(int(status.split()[0])) + try: + tornado_handler.set_status(int(status.split()[0])) + except RuntimeError: # pragma: no cover + # for websocket connections Tornado does not accept a response, since + # it already emitted the 101 status code + return for header, value in headers: tornado_handler.set_header(header, value) tornado_handler.write(payload)