Skip to content

Commit

Permalink
fix WebSocketClientConnection circle reference
Browse files Browse the repository at this point in the history
to itself
  • Loading branch information
qcha0 committed May 20, 2020
1 parent 36c9a4c commit 4d5051a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tornado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,12 @@ def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> Non
self.protocol = None # type: ignore

def on_connection_close(self) -> None:
if not self.connect_future.done():
if self.connect_future and not self.connect_future.done():
self.connect_future.set_exception(StreamClosedError())
self._on_message(None)
self.tcp_client.close()
super(WebSocketClientConnection, self).on_connection_close()
self.connect_future = None

def on_ws_connection_close(
self, close_code: Optional[int] = None, close_reason: Optional[str] = None
Expand All @@ -1449,7 +1450,7 @@ def on_ws_connection_close(
self.on_connection_close()

def _on_http_response(self, response: httpclient.HTTPResponse) -> None:
if not self.connect_future.done():
if self.connect_future and not self.connect_future.done():
if response.error:
self.connect_future.set_exception(response.error)
else:
Expand Down

0 comments on commit 4d5051a

Please sign in to comment.