UNUSUALxd commited on
Commit
3cdd115
·
verified ·
1 Parent(s): 82e2b90

Update bot/proxy_manager.py

Browse files
Files changed (1) hide show
  1. bot/proxy_manager.py +12 -2
bot/proxy_manager.py CHANGED
@@ -4,6 +4,7 @@ import asyncio
4
  import aiohttp
5
  from utils.logger import log
6
  from bot.database import db
 
7
 
8
  class ProxyManager:
9
  def __init__(self):
@@ -123,17 +124,26 @@ class ProxyManager:
123
  def handle_runtime_routing_fault(self, dead_hostname: str):
124
  """
125
  Executes an instant, hot-swap redirection sequence.
126
- Rotates out a failing proxy from the pool path dynamically.
127
  """
128
  log(f"🛡️ Dynamic Routing Fault Caught on route: {dead_hostname}")
129
  best_nodes = self.get_best_proxies(len(self.proxies))
 
130
 
131
  fallback_node = None
 
132
  for p in best_nodes:
133
- if p["hostname"] != dead_hostname:
134
  fallback_node = p
135
  break
136
 
 
 
 
 
 
 
 
137
  if fallback_node:
138
  log(f"🔄 Hot-Swap Target Selected: {fallback_node['hostname']} ({fallback_node['ping']}ms)")
139
  return {
 
4
  import aiohttp
5
  from utils.logger import log
6
  from bot.database import db
7
+ from bot.state import state
8
 
9
  class ProxyManager:
10
  def __init__(self):
 
124
  def handle_runtime_routing_fault(self, dead_hostname: str):
125
  """
126
  Executes an instant, hot-swap redirection sequence.
127
+ Rotates out a failing proxy from the pool path dynamically, avoiding active locks.
128
  """
129
  log(f"🛡️ Dynamic Routing Fault Caught on route: {dead_hostname}")
130
  best_nodes = self.get_best_proxies(len(self.proxies))
131
+ allocated_proxies = state.get("allocated_proxies", set())
132
 
133
  fallback_node = None
134
+ # Priority 1: Find an alive proxy that is not currently locked by another camper thread
135
  for p in best_nodes:
136
+ if p["hostname"] != dead_hostname and p["hostname"] not in allocated_proxies:
137
  fallback_node = p
138
  break
139
 
140
+ # Priority 2: Fallback to any unlocked or available alive node if allocation limits are saturated
141
+ if not fallback_node:
142
+ for p in best_nodes:
143
+ if p["hostname"] != dead_hostname:
144
+ fallback_node = p
145
+ break
146
+
147
  if fallback_node:
148
  log(f"🔄 Hot-Swap Target Selected: {fallback_node['hostname']} ({fallback_node['ping']}ms)")
149
  return {