2025-09-17 17:59:37.086 [INFO] MAVSDK server already running on port 50040. Terminating...
2025-09-17 17:59:42.113 [WARNING] Process with PID: 5603 did not terminate gracefully. Killing it.
2025-09-17 17:59:38.075 [ERROR] grpc._channel._MultiThreadedRendezvous: Socket closed
Root causes:
# OLD (problematic in containers)
process.wait(timeout=5)
connection_timeout = 10
# NEW (container-friendly)
process.wait(timeout=10) # Graceful termination
time.sleep(3.0) # Port cleanup
connection_timeout = 30 # Extended connection wait
max_attempts = 3 # Multiple retry attempts
Your container logs will now show:
[INFO] MAVSDK server already running... Terminating existing server
[INFO] Terminated existing MAVSDK server with PID: 5603
[INFO] Waiting for port cleanup after server termination...
[INFO] Starting new MAVSDK server...
[INFO] Waiting for MAVSDK server to be ready...
[INFO] MAVSDK server is ready and listening on gRPC port
[INFO] Connection attempt 1/3
[INFO] Drone connected via MAVSDK server at 127.0.0.1:50040
✅ No more “Socket closed” errors ✅ No more connection timeouts ✅ No more port conflicts ✅ Reliable container startup
Clean, optimized, container-friendly MAVSDK management.