mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-05 08:45:13 +00:00
Add timeout when connecting
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user