timeout bedrock status comms

This commit is contained in:
MeRuslan
2021-07-27 04:12:44 +03:00
parent 1aef08b293
commit 3b0231fd8c

View File

@@ -1,3 +1,4 @@
import asyncio
import socket import socket
import struct import struct
from time import perf_counter from time import perf_counter
@@ -56,10 +57,11 @@ class BedrockServerStatus:
start = perf_counter() start = perf_counter()
try: 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) await asyncio.wait_for(stream.send(self.request_status_data), timeout=self.timeout)
data, _ = await stream.recv() data, _ = await asyncio.wait_for(stream.recv(), timeout=self.timeout)
finally: finally:
try: try:
stream.close() stream.close()