summaryrefslogtreecommitdiff
path: root/websocket
diff options
context:
space:
mode:
authorBoris Feld <lothiraldan@gmail.com>2019-02-20 20:44:49 +0100
committerBoris Feld <lothiraldan@gmail.com>2019-02-20 20:44:49 +0100
commit983392960564be59935d283f187b0722e2c6cfa4 (patch)
treebe85f12f04a23b6ab47dc7c099d2b4036f7c9a29 /websocket
parent2c18d28f3596acfd269fa568fbf85ff9ca2b97fb (diff)
downloadwebsocket-client-983392960564be59935d283f187b0722e2c6cfa4.tar.gz
Fix `WebSocket.close` in multi-threaded environments
In multi-threaded environment where the `WebsocketApp` lives in another thread than the main thread, the main thread might call `WebsocketApp.close` which will sends the closing message to the backend and then wait for the answer. This will likely makes the following loop https://github.com/websocket-client/websocket-client/blob/master/websocket/_app.py#L49 to ends which will calls https://github.com/websocket-client/websocket-client/blob/master/websocket/_app.py#L235. The second call will happened in the `WebsocketApp` thread and as the socket is already marked as not connected anymore, the second thread will jump directly into the `WebSocket.shutdown` method which will abruptly close the socket, stopping all in-progress sending and making the first call to `WebSocket.close` to crash as `self.sock` is replaces by None.
Diffstat (limited to 'websocket')
-rw-r--r--websocket/_core.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/websocket/_core.py b/websocket/_core.py
index c91ad63..6fb89b7 100644
--- a/websocket/_core.py
+++ b/websocket/_core.py
@@ -425,7 +425,7 @@ class WebSocket(object):
except:
pass
- self.shutdown()
+ self.shutdown()
def abort(self):
"""