From 3b0231fd8c6f77635107bdcf1cfa7a9784f2f9e6 Mon Sep 17 00:00:00 2001 From: MeRuslan Date: Tue, 27 Jul 2021 04:12:44 +0300 Subject: [PATCH] timeout bedrock status comms --- mcstatus/bedrock_status.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mcstatus/bedrock_status.py b/mcstatus/bedrock_status.py index 0f39beb..fb9becd 100644 --- a/mcstatus/bedrock_status.py +++ b/mcstatus/bedrock_status.py @@ -1,3 +1,4 @@ +import asyncio import socket import struct from time import perf_counter @@ -56,10 +57,11 @@ class BedrockServerStatus: start = perf_counter() try: - stream = await asyncio_dgram.connect((self.host, self.port)) + conn = asyncio_dgram.connect((self.host, self.port)) + stream = await asyncio.wait_for(conn, timeout=self.timeout) - await stream.send(self.request_status_data) - data, _ = await stream.recv() + await asyncio.wait_for(stream.send(self.request_status_data), timeout=self.timeout) + data, _ = await asyncio.wait_for(stream.recv(), timeout=self.timeout) finally: try: stream.close()