fix proxy
This commit is contained in:
@@ -155,9 +155,9 @@ class BrowserService:
|
||||
_set_real_ip(None)
|
||||
logger.info("Direct connection")
|
||||
except asyncio.CancelledError:
|
||||
# Гарантируем освобождение прокси даже при отмене задачи
|
||||
# Задача отменена — прокси не виноват, освобождаем без штрафа
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, success=False)
|
||||
await self.proxy_manager.release_proxy(proxy, success=True)
|
||||
raise
|
||||
|
||||
if proxy_config:
|
||||
@@ -167,15 +167,6 @@ class BrowserService:
|
||||
humanize=True,
|
||||
exclude_addons=[DefaultAddons.UBO],
|
||||
proxy=proxy_config,
|
||||
firefox_prefs={
|
||||
# Запрещаем WebRTC использовать локальные IP-кандидаты
|
||||
"media.peerconnection.ice.no_host": True,
|
||||
# Только ICE через прокси — блокирует утечку реального IP
|
||||
"media.peerconnection.ice.proxy_only_if_behind_proxy": True,
|
||||
# DNS только через прокси (предотвращает DNS-утечку)
|
||||
"network.dns.disablePrefetch": True,
|
||||
"network.prefetch-next": False,
|
||||
},
|
||||
)
|
||||
if proxy_locale:
|
||||
camoufox_kwargs["locale"] = proxy_locale
|
||||
@@ -204,11 +195,12 @@ class BrowserService:
|
||||
await self.socks5_pool.release(proxy)
|
||||
|
||||
if is_proxy_dead:
|
||||
logger.warning(f"Visit attempt {attempt + 1} proxy connection failed, retrying with new")
|
||||
logger.warning(f"Visit attempt {attempt + 1} proxy connection failed, retrying with new proxy")
|
||||
continue
|
||||
elif is_load_error:
|
||||
logger.warning(f"Visit attempt {attempt + 1} page load error (proxy ok), retrying")
|
||||
continue
|
||||
# Ошибка загрузки — не меняем прокси, просто возвращаем результат
|
||||
# (сайт мог быть временно недоступен, прокси ок)
|
||||
logger.warning(f"Visit attempt {attempt + 1} page load error: {result.error or 'unknown'}")
|
||||
|
||||
return result
|
||||
|
||||
@@ -222,7 +214,8 @@ class BrowserService:
|
||||
except Exception as e:
|
||||
logger.error(f"Visit error: {e}", exc_info=True)
|
||||
if proxy:
|
||||
await self.proxy_manager.release_proxy(proxy, success=False)
|
||||
# Ошибка кода/браузера — прокси не виноват
|
||||
await self.proxy_manager.release_proxy(proxy, success=True)
|
||||
if use_socks5:
|
||||
await self.socks5_pool.release(proxy)
|
||||
return VisitResult(url=url, success=False, error=str(e))
|
||||
|
||||
Reference in New Issue
Block a user