Raise ProxyConnectionError instead looping forever (#621)

We shouldn't try reconnecting when using a proxy if what's
unavailable is the proxy server (and not Telegram servers).
This commit is contained in:
Dmitry Bukhta 2018-02-20 17:58:51 +03:00 committed by Lonami Exo
parent ea0da8fc0e
commit 0731a1d698

View File

@ -8,6 +8,11 @@ from datetime import timedelta
from io import BytesIO, BufferedWriter
from threading import Lock
try:
import socks
except ImportError:
socks = None
MAX_TIMEOUT = 15 # in seconds
CONN_RESET_ERRNOS = {
errno.EBADF, errno.ENOTSOCK, errno.ENETUNREACH,
@ -70,6 +75,9 @@ class TcpClient:
self._socket.connect(address)
break # Successful connection, stop retrying to connect
except OSError as e:
# Stop retrying to connect if proxy connection error occurred
if socks and isinstance(e, socks.ProxyConnectionError):
raise
# There are some errors that we know how to handle, and
# the loop will allow us to retry
if e.errno in (errno.EBADF, errno.ENOTSOCK, errno.EINVAL,