Skip to content

mavtcp: mark closed sockets as disconnected without autoreconnect#1193

Open
vvezre wants to merge 1 commit intoArduPilot:masterfrom
vvezre:codex/mavtcp-disconnect-detection
Open

mavtcp: mark closed sockets as disconnected without autoreconnect#1193
vvezre wants to merge 1 commit intoArduPilot:masterfrom
vvezre:codex/mavtcp-disconnect-detection

Conversation

@vvezre
Copy link
Copy Markdown
Contributor

@vvezre vvezre commented Mar 30, 2026

Summary

  • mark TCP sockets as disconnected when EOF or connection-reset is observed, even when autoreconnect=False
  • make mavtcp.recv() raise ConnectionError if no socket is available after reconnect logic
  • keep reconnect behavior unchanged for autoreconnect=True
  • add regression tests for EOF and ECONNRESET disconnect handling

Why

mavtcp currently leaves self.port set after disconnect events when auto-reconnect is disabled.
That makes disconnect detection difficult and can cause repeated EOF handling without a stable disconnected state.

Testing

  • python -m pytest C:\Users\woshe\Documents\Playground\pymavlink-git\tests\test_mavtcp.py -q
  • python -m py_compile C:\Users\woshe\Documents\Playground\pymavlink-git\mavutil.py C:\Users\woshe\Documents\Playground\pymavlink-git\tests\test_mavtcp.py

Closes #742


def close(self):
self.port.close()
if self.port is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this guard needed now?

Comment on lines +9 to +24
try:
from pymavlink import mavutil
except ModuleNotFoundError:
repo_root = Path(__file__).resolve().parents[1]
pkg_spec = importlib.util.spec_from_file_location(
"pymavlink",
repo_root / "__init__.py",
submodule_search_locations=[str(repo_root)],
)
assert pkg_spec is not None and pkg_spec.loader is not None
pymavlink_pkg = importlib.util.module_from_spec(pkg_spec)
sys.modules["pymavlink"] = pymavlink_pkg
pkg_spec.loader.exec_module(pymavlink_pkg)
from pymavlink import mavutil


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please simplify to import like the other tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TCP Cannot cannot check for tcp disconnection to recover

2 participants