add drain lock
@@ -64,6 +64,8 @@ class Stream:
self.reader = reader
self.writer = writer
+ self.drain_lock = asyncio.Lock()
+
async def read_packet(self) -> cj.ClassyDict:
(length,) = struct.unpack(">i", await self.reader.read(LENGTH_LENGTH)) # read the length of the upcoming packet
data = await self.reader.read(length) # read the rest of the packet
@@ -78,6 +80,7 @@ class Stream:
raise ValueError("Packet is too big to send...")
self.writer.write(packet)
+ async with self.drain_lock:
await self.writer.drain()
async def close(self) -> None:
