mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 17:43:32 +00:00
Don't retry forever
This commit is contained in:
parent
68424d3291
commit
8339f493bc
@ -32,6 +32,8 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class Auth:
|
class Auth:
|
||||||
|
MAX_RETRIES = 5
|
||||||
|
|
||||||
CURRENT_DH_PRIME = int(
|
CURRENT_DH_PRIME = int(
|
||||||
"C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F"
|
"C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F"
|
||||||
"48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C37"
|
"48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C37"
|
||||||
@ -76,9 +78,10 @@ class Auth:
|
|||||||
https://core.telegram.org/mtproto/auth_key
|
https://core.telegram.org/mtproto/auth_key
|
||||||
https://core.telegram.org/mtproto/samples-auth_key
|
https://core.telegram.org/mtproto/samples-auth_key
|
||||||
"""
|
"""
|
||||||
|
retries_left = self.MAX_RETRIES
|
||||||
|
|
||||||
# The server may close the connection at any time, causing the auth key creation to fail.
|
# The server may close the connection at any time, causing the auth key creation to fail.
|
||||||
# If that happens, just try again until it succeed.
|
# If that happens, just try again up to MAX_RETRIES times.
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
log.info("Start creating a new auth key on DC{}".format(self.dc_id))
|
log.info("Start creating a new auth key on DC{}".format(self.dc_id))
|
||||||
@ -243,6 +246,11 @@ class Auth:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if retries_left:
|
||||||
|
retries_left -= 1
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
log.warning("Auth key creation failed. Let's try again: {}".format(repr(e)))
|
log.warning("Auth key creation failed. Let's try again: {}".format(repr(e)))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user