Ensure that keep alive threads are closed when a websocket closes.
The library worked with the assumption that whenever the recv call for the websocket would lead to a closure, the close method would be called to signal closure and as a result our close method would be called. This assumption turned out to be false as the websockets library would instead call an internal function named close_connection instead. So to solve our problem we need to override this function instead of close.
This commit is contained in:
parent
dd8c32ceff
commit
0b6e74ebec
@ -318,6 +318,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
state.sequence = None
|
state.sequence = None
|
||||||
state.session_id = None
|
state.session_id = None
|
||||||
if data == True:
|
if data == True:
|
||||||
|
yield from self.close()
|
||||||
raise ResumeWebSocket()
|
raise ResumeWebSocket()
|
||||||
|
|
||||||
yield from self.identify()
|
yield from self.identify()
|
||||||
@ -459,11 +460,11 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
self._connection._remove_voice_client(guild_id)
|
self._connection._remove_voice_client(guild_id)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self, code=1000, reason=''):
|
def close_connection(self, force=False):
|
||||||
if self._keep_alive:
|
if self._keep_alive:
|
||||||
self._keep_alive.stop()
|
self._keep_alive.stop()
|
||||||
|
|
||||||
yield from super().close(code, reason)
|
yield from super().close_connection(force=force)
|
||||||
|
|
||||||
class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
||||||
"""Implements the websocket protocol for handling voice connections.
|
"""Implements the websocket protocol for handling voice connections.
|
||||||
@ -605,10 +606,10 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
raise ConnectionClosed(e) from e
|
raise ConnectionClosed(e) from e
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self, code=1000, reason=''):
|
def close_connection(self, force=False):
|
||||||
if self._keep_alive:
|
if self._keep_alive:
|
||||||
self._keep_alive.stop()
|
self._keep_alive.stop()
|
||||||
|
|
||||||
yield from super().close(code, reason)
|
yield from super().close_connection(force=force)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user