Skip to content

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

@GuillaumeLaine
Copy link
Member Author

Closing because stale

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