Skip to content

Commit d9f4ca4

Browse files
committed
feat: enhance port availability search with detailed logging and troubleshooting guidance
1 parent 74b2837 commit d9f4ca4

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

backend/main.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ def find_available_port(preferred_ports, host='0.0.0.0'):
386386
"""Trouve un port disponible parmi la liste fournie"""
387387
import socket
388388

389+
logger.info(f"🔍 Searching for available port among: {preferred_ports}")
390+
389391
for port in preferred_ports:
390392
try:
391393
# Tester si le port est disponible
@@ -395,12 +397,17 @@ def find_available_port(preferred_ports, host='0.0.0.0'):
395397
sock.close()
396398

397399
if result != 0: # Port disponible
400+
logger.info(f"✅ Port {port} is available - Selected!")
398401
return port
402+
else:
403+
logger.info(f"❌ Port {port} is already in use - Trying next...")
399404
except Exception as e:
400405
logger.debug(f"Error testing port {port}: {e}")
406+
logger.info(f"⚠️ Port {port} - Test error - Trying next...")
401407
continue
402408

403409
# Si aucun port de la liste n'est disponible, laisser le système en choisir un
410+
logger.error("❌ NO available port found in the list!")
404411
return None
405412

406413
if __name__ == '__main__':
@@ -426,12 +433,27 @@ def find_available_port(preferred_ports, host='0.0.0.0'):
426433
# Trouver un port disponible
427434
if args.port:
428435
selected_port = args.port
429-
logger.info(f"Using specified port: {selected_port}")
436+
logger.info(f"📌 Using specified port: {selected_port}")
430437
else:
438+
logger.info("🔄 No port specified, searching for available port...")
431439
selected_port = find_available_port(AVAILABLE_PORTS, args.host)
432440
if selected_port is None:
433-
logger.error("Could not find any available port from the configured list!")
434-
print("❌ Aucun port disponible trouvé. Veuillez fermer certaines applications et réessayer.")
441+
logger.error("❌ Could not find any available port from the configured list!")
442+
print("\n" + "=" * 70)
443+
print("❌ ERROR: No available ports found")
444+
print("=" * 70)
445+
print(f"Tested ports: {AVAILABLE_PORTS}")
446+
print("\n💡 Troubleshooting steps:")
447+
print(" 1. Close applications using these ports (check Task Manager)")
448+
print(" 2. Close browser tabs connected to the bot (Chrome/Firefox/Edge)")
449+
print(" 3. Kill any hung Python processes: taskkill /F /IM python.exe")
450+
print(" 4. Restart your computer if the issue persists")
451+
print("\n🔍 Common causes:")
452+
print(" - Previous bot instance still running")
453+
print(" - Browser keeping WebSocket connection alive")
454+
print(" - Antivirus/Firewall blocking ports")
455+
print(" - Another service using the same ports")
456+
print("=" * 70 + "\n")
435457
sys.exit(1)
436458
logger.info(f"Found available port: {selected_port}")
437459

0 commit comments

Comments
 (0)