Skip to content

feat: add timeout handling in TCPClient #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GuillaumeLaine
Copy link
Member

@GuillaumeLaine GuillaumeLaine commented Jul 15, 2025

Changes

Adds a connection timeout mechanism to the TCPClient constructor to prevent indefinite blocking when connecting to unreachable IP addresses.

Without this change, the first unreachable IP fails quickly and the second connect() call hangs indefinitely, preventing fallback to subsequent IPs. For example:

auto physical_1 = mav::TCPClient(1.1.1.1, 1234);
// Connect failed (Connection refused)

auto physical_2 = mav::TCPClient(2.2.2.2, 1234);
// Hangs indefinitely...

// ...Never reaches subsequent addresses
auto physical_3 = mav::TCPClient(3.3.3.3, 1234);

With this change, all configured IPs will be tried.

For more context, see Trying to connect() multiple times in TCP

@GuillaumeLaine
Copy link
Member Author

GuillaumeLaine commented Jul 15, 2025

Just saw a similar solution was implemented previously here: #47

This PR implements a similar solution by making connect() non-blocking. Additionally, this PR checks on completion of any non-blocking connect() calls before timing out. The linked PR may leave "in progress" connections running in the background. If connect() returns EINPROGRESS, we should use select() to check for completion

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.

1 participant