2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-09-05 00:35:10 +00:00

Add timeout when connecting

This commit is contained in:
Dan
2018-06-17 18:44:45 +02:00
parent 0a6583a43c
commit 52354b93d0

View File

@@ -25,6 +25,7 @@ log = logging.getLogger(__name__)
class Connection:
TIMEOUT = 10
MAX_RETRIES = 3
MODES = {
@@ -49,8 +50,8 @@ class Connection:
try:
log.info("Connecting...")
await self.protocol.connect(self.address)
except OSError:
await asyncio.wait_for(self.protocol.connect(self.address), Connection.TIMEOUT)
except (OSError, asyncio.TimeoutError):
self.protocol.close()
await asyncio.sleep(1)
else: