Skip to content

Commit 5da2c4d

Browse files
authored
feat: Utilise reconnection lock for packet sending. (#1083)
1 parent 0312190 commit 5da2c4d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

interactions/api/gateway/client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -959,16 +959,18 @@ async def _send_packet(self, data: Dict[str, Any]) -> None:
959959
"""
960960
_data = dumps(data) if isinstance(data, dict) else data
961961
packet: str = _data.decode("utf-8") if isinstance(_data, bytes) else _data
962+
log.debug(packet)
962963

963-
if data["op"] != OpCodeType.HEARTBEAT.value:
964-
# This is because the ratelimiter limits already accounts for this.
965-
await self._ratelimiter.block()
964+
async with self.reconnect_lock: # needs to lock while it reconnects.
966965

967-
if self._client is not None: # this mitigates against another edge case.
968-
self._last_send = perf_counter()
969-
log.debug(packet)
966+
if data["op"] != OpCodeType.HEARTBEAT.value:
967+
# This is because the ratelimiter limits already accounts for this.
968+
await self._ratelimiter.block()
970969

971-
await self._client.send_str(packet)
970+
if self._client is not None: # this mitigates against another edge case.
971+
self._last_send = perf_counter()
972+
973+
await self._client.send_str(packet)
972974

973975
async def __identify(
974976
self, shard: Optional[List[Tuple[int]]] = None, presence: Optional[ClientPresence] = None

0 commit comments

Comments
 (0)