mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-27 20:37:54 +00:00
Don't try to indefinitely reconnect at Connection layer
This commit is contained in:
parent
00b983ccc3
commit
81d3d5956c
@ -26,6 +26,8 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
MAX_RETRIES = 5
|
||||||
|
|
||||||
MODES = {
|
MODES = {
|
||||||
0: TCPFull,
|
0: TCPFull,
|
||||||
1: TCPAbridged,
|
1: TCPAbridged,
|
||||||
@ -40,7 +42,7 @@ class Connection:
|
|||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
while True:
|
for i in range(Connection.MAX_RETRIES):
|
||||||
self.connection = self.mode(self.proxy)
|
self.connection = self.mode(self.proxy)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -51,6 +53,8 @@ class Connection:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
raise TimeoutError
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user