diff options
| author | Boris Feld <lothiraldan@gmail.com> | 2019-02-20 20:44:49 +0100 |
|---|---|---|
| committer | Boris Feld <lothiraldan@gmail.com> | 2019-02-20 20:44:49 +0100 |
| commit | 983392960564be59935d283f187b0722e2c6cfa4 (patch) | |
| tree | be85f12f04a23b6ab47dc7c099d2b4036f7c9a29 /websocket | |
| parent | 2c18d28f3596acfd269fa568fbf85ff9ca2b97fb (diff) | |
| download | websocket-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.py | 2 |
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): """ |
