From b9d64de19f25165eff3e72ab5e7712f24cb86c7e Mon Sep 17 00:00:00 2001 From: Le Bao Hiep Date: Sun, 16 Jan 2022 02:27:35 +0000 Subject: [PATCH] Use socket.sendall to send packets If only some of the data was transmitted, writelines does not attempt to send the remaining data, while sendall continues to send data until either all data has been sent or an error occurs. --- dmoj/packet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dmoj/packet.py b/dmoj/packet.py index 55a3f3339..287a88488 100644 --- a/dmoj/packet.py +++ b/dmoj/packet.py @@ -110,7 +110,6 @@ def _connect(self): log.info('Starting handshake with: [%s]:%s', self.host, self.port) self.input = self.conn.makefile('rb') - self.output = self.conn.makefile('wb', 0) self.handshake(problems, versions, self.name, self.key) log.info('Judge "%s" online: [%s]:%s', self.name, self.host, self.port) @@ -238,7 +237,8 @@ def _send_packet(self, packet: dict): raw = zlib.compress(utf8bytes(json.dumps(packet))) with self._lock: try: - self.output.writelines((PacketManager.SIZE_PACK.pack(len(raw)), raw)) + assert self.conn is not None + self.conn.sendall(PacketManager.SIZE_PACK.pack(len(raw)) + raw) except Exception: # connection reset by peer log.exception('Exception while sending packet to site, will not attempt to reconnect! Quitting judge.') os._exit(1)