refactor: replace immediate port kill with a 15-second wait for port release in cleanup function

This commit is contained in:
Donato Capitella
2026-05-15 08:58:16 +01:00
parent 765f635381
commit adf72bdda7
+12 -12
View File
@@ -186,21 +186,21 @@ def kill_port_holder(port: int):
print(f" {result.stdout.strip()}") print(f" {result.stdout.strip()}")
def cleanup(port: int): def cleanup(port: int) -> bool:
"""Full cleanup: stop stale containers and free the port.""" """Full cleanup: stop stale containers and wait for port to be free."""
# Stop any leftover benchmark container
stop_container() stop_container()
# Check for port conflicts # Wait for port to be released (podman proxy takes a moment after stop)
if not check_port_free(port): for i in range(15): # up to 15 seconds
print(f" ⚠️ Port {port} is already in use — attempting cleanup...") if check_port_free(port):
kill_port_holder(port) return True
if i == 0:
print(f" ⏳ Waiting for port {port} to be released...")
time.sleep(1) time.sleep(1)
if not check_port_free(port):
print(f" ❌ Port {port} is still in use after cleanup. Aborting.") print(f" ❌ Port {port} still in use after 15s. Something else is holding it.")
return False return False
print(f" ✅ Port {port} is now free.")
return True
def stop_container(): def stop_container():