worker: check tor before claiming work
All checks were successful
CI / syntax-check (push) Successful in 3s
CI / memory-leak-check (push) Successful in 11s

This commit is contained in:
Username
2025-12-28 16:09:40 +01:00
parent 0d7d2dce70
commit 2bc00d3ebd

40
ppf.py
View File

@@ -498,8 +498,6 @@ def worker_main(config):
jobs_completed = 0 jobs_completed = 0
proxies_tested = 0 proxies_tested = 0
start_time = time.time() start_time = time.time()
last_tor_check = time.time()
tor_check_interval = 300 # Check Tor every 5 minutes
current_tor_ip = None current_tor_ip = None
consecutive_tor_failures = 0 consecutive_tor_failures = 0
worker_profiling = config.args.profile or config.common.profiling worker_profiling = config.args.profile or config.common.profiling
@@ -546,33 +544,33 @@ def worker_main(config):
try: try:
while True: while True:
# Periodic Tor health check # Tor check before claiming work - don't claim if Tor is down
now = time.time()
if now - last_tor_check > tor_check_interval:
working, tor_ip = check_tor_connectivity(config.torhosts) working, tor_ip = check_tor_connectivity(config.torhosts)
last_tor_check = now if not working:
if working:
consecutive_tor_failures = 0
if tor_ip != current_tor_ip:
_log('tor circuit rotated: %s' % tor_ip, 'info')
current_tor_ip = tor_ip
# Send periodic heartbeat
try:
worker_send_heartbeat(server_url, wstate['worker_key'], True, tor_ip, worker_profiling)
except NeedReregister:
do_register()
else:
consecutive_tor_failures += 1 consecutive_tor_failures += 1
_log('tor connectivity failed (consecutive: %d)' % consecutive_tor_failures, 'warn') _log('tor down before claiming work (consecutive: %d)' % consecutive_tor_failures, 'warn')
if consecutive_tor_failures >= 2:
_log('tor appears down, pausing work', 'error')
try: try:
worker_send_heartbeat(server_url, wstate['worker_key'], False, None, worker_profiling) worker_send_heartbeat(server_url, wstate['worker_key'], False, None, worker_profiling)
except NeedReregister: except NeedReregister:
do_register() do_register()
if consecutive_tor_failures >= 2:
_log('tor appears down, waiting before claiming work', 'error')
working, current_tor_ip = wait_for_tor() working, current_tor_ip = wait_for_tor()
consecutive_tor_failures = 0 consecutive_tor_failures = 0
last_tor_check = time.time() else:
time.sleep(10)
continue
else:
consecutive_tor_failures = 0
if tor_ip != current_tor_ip:
if current_tor_ip:
_log('tor circuit rotated: %s' % tor_ip, 'info')
current_tor_ip = tor_ip
# Send heartbeat to manager
try:
worker_send_heartbeat(server_url, wstate['worker_key'], True, tor_ip, worker_profiling)
except NeedReregister:
do_register()
# Get work from master # Get work from master
try: try: