mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Workaround #1134 by early checking if proxy closes connection
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
@@ -92,6 +93,28 @@ class TcpMTProxy(ObfuscatedConnection):
|
||||
packet_codec = None
|
||||
obfuscated_io = MTProxyIO
|
||||
|
||||
async def _connect(self, timeout=None, ssl=None):
|
||||
await super()._connect(timeout=timeout, ssl=ssl)
|
||||
|
||||
# Wait for EOF for 2 seconds (or if _wait_for_data's definition
|
||||
# is missing or different, just sleep for 2 seconds). This way
|
||||
# we give the proxy a chance to close the connection if the current
|
||||
# codec (which the proxy detects with the data we sent) cannot
|
||||
# be used for this proxy. This is a work around for #1134.
|
||||
# TODO Sleeping for N seconds may not be the best solution
|
||||
# TODO This fix could be welcome for HTTP proxies as well
|
||||
try:
|
||||
await asyncio.wait_for(self._reader._wait_for_data('proxy'), 2)
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
except Exception:
|
||||
await asyncio.sleep(2)
|
||||
|
||||
if self._reader.at_eof():
|
||||
self.disconnect()
|
||||
raise ConnectionError(
|
||||
'Proxy closed the connection after sending initial payload')
|
||||
|
||||
@staticmethod
|
||||
def address_info(proxy_info):
|
||||
if proxy_info is None:
|
||||
|
Reference in New Issue
Block a user