MavProxy not connecting after installing Gazebo plugin

I was following the SITL instructions on the main docs site (Setting up SITL on Linux — Dev documentation); i am on Ubuntu 20.04. I got the SITL with MavProxy working just like in the instructions; the command sim_vehicle.py --console --map launching everything as the last step.

I then moved on to get it to work with Gazebo following Using Gazebo Simulator with SITL — Dev documentation, I installed Gazebo9, the dev dependencies, the khancyr gazebo plugin.

Launching Gazebo with gazebo --verbose worlds/iris_arducopter_runway.world and then the SITL with

cd ~/ardupilot/ArduPlane
…/Tools/autotest/sim_vehicle.py -f gazebo-zephyr --console --map

I get an error

SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: “mavproxy.py” “–map” “–console” “–out” “127.0.0.1:14550” “–out” “127.0.0.1:14551” “–master” “tcp:127.0.0.1:5760” “–sitl” “127.0.0.1:5501”
RiTW: Starting ArduPlane : /home/hermamr1/ardupilot/build/sitl/bin/arduplane -S --model gazebo-zephyr --speedup 1 --slave 0 --defaults /home/hermamr1/ardupilot/Tools/autotest/default_params/gazebo-zephyr.parm -I0
Connect tcp:127.0.0.1:5760 source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Failed to connect to tcp:127.0.0.1:5760 : [Errno 111] Connection refused
SIM_VEHICLE: Killing tasks

It seems that MavProxy isn’t connecting with the SITL anymore? But I am not sure why that would be. And now when I try to run without Gazebo using the steps at the top of my post I get the same error; so it seems not related to Gazebo, but happened after trying to use Gazebo for the first time?

Why would I get this error, I am really new to ArduPilot and ArduPlane so maybe it’s something real obvious I am missing but stepping through everything I did I can’t figure it out.

After some debugging, I determined the problem. The startup script /Tools/autotest/sim_vehicle.py starts mavproxy and then mavproxy will attempt to connect for a short time before failing, closing and then causing sim_vehicle.py to end. The issue is if Arduplane hasn’t completely started to the point of waiting for connections then mavproxy has nothing to connect to causing the above failure and premature shutdown. In most cases I doubt this happens to most people, Arduplane starts up quick; however, I was observing that on an SSH connection with a higher latency than one sees on a local network that Arduplane does take an extra amount of time to fully start and causes failure. I sleep() in sim_vehicle before starting mavproxy solved my issue; however, that is not ideal. An issue was created, sim_vehicle.py could start mavproxy before ArduPlane has started and is waiting for connection causing premature exit · Issue #19314 · ArduPilot/ardupilot · GitHub.