feat: Utilise reconnection lock for packet sending.
@@ -959,6 +959,9 @@ class WebSocketClient:
"""
_data = dumps(data) if isinstance(data, dict) else data
packet: str = _data.decode("utf-8") if isinstance(_data, bytes) else _data
+ log.debug(packet)
+
+ async with self.reconnect_lock: # needs to lock while it reconnects.
if data["op"] != OpCodeType.HEARTBEAT.value:
# This is because the ratelimiter limits already accounts for this.
@@ -966,7 +969,6 @@ class WebSocketClient:
if self._client is not None: # this mitigates against another edge case.
self._last_send = perf_counter()
- log.debug(packet)
await self._client.send_str(packet)
