Skip to content

Commit 81d3d59

Browse files
committed
Don't try to indefinitely reconnect at Connection layer
1 parent 00b983c commit 81d3d59

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pyrogram/connection/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727

2828
class Connection:
29+
MAX_RETRIES = 5
30+
2931
MODES = {
3032
0: TCPFull,
3133
1: TCPAbridged,
@@ -40,7 +42,7 @@ def __init__(self, address: tuple, proxy: dict, mode: int = 1):
4042
self.connection = None
4143

4244
def connect(self):
43-
while True:
45+
for i in range(Connection.MAX_RETRIES):
4446
self.connection = self.mode(self.proxy)
4547

4648
try:
@@ -51,6 +53,8 @@ def connect(self):
5153
time.sleep(1)
5254
else:
5355
break
56+
else:
57+
raise TimeoutError
5458

5559
def close(self):
5660
self.connection.close()

0 commit comments

Comments
 (0)