tcp_client_connection: fix server closing the connection#2683
Merged
julianoes merged 1 commit intomavlink:mainfrom Oct 9, 2025
Merged
tcp_client_connection: fix server closing the connection#2683julianoes merged 1 commit intomavlink:mainfrom
julianoes merged 1 commit intomavlink:mainfrom
Conversation
recv() returns 0 when the socket is shut down. The previous logic would immediately try again to call recv(), resulting in busy looping, without ever trying to reconnect. This patch adds a sleep and periodically tries to reconnect. Also, it closes the socket when the setup of the connection fails. There's still a bit of spamming during disconnected state: [10:40:20|Info ] TCP connection closed, trying to reconnect... (tcp_client_connection.cpp:215) [10:40:22|Error] Connect error: Connection refused (tcp_client_connection.cpp:103) [10:40:22|Error] Sending message failed (mavsdk_impl.cpp:764) [10:40:23|Error] Connect error: Connection refused (tcp_client_connection.cpp:103) [10:40:23|Error] Sending message failed (mavsdk_impl.cpp:764) [10:40:23|Info ] heartbeats timed out (system_impl.cpp:370) [10:40:24|Error] Connect error: Connection refused (tcp_client_connection.cpp:103) [10:40:24|Error] Sending message failed (mavsdk_impl.cpp:764) [10:40:25|Error] Connect error: Connection refused (tcp_client_connection.cpp:103) [10:40:25|Error] Sending message failed (mavsdk_impl.cpp:764) [10:40:26|Error] Connect error: Connection refused (tcp_client_connection.cpp:103) [10:40:26|Error] Sending message failed (mavsdk_impl.cpp:764) [10:40:27|Debug] Discovered 1 component(s) (system_impl.cpp:607)
|
julianoes
approved these changes
Oct 9, 2025
Collaborator
julianoes
left a comment
There was a problem hiding this comment.
Thank you! I think that makes sense.
Any hints how you discovered this, or what sort of system test I could add to cover this?
Member
Author
|
I tested against mavlink-router using its default TCP server (using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



recv() returns 0 when the socket is shut down. The previous logic would immediately try again to call recv(), resulting in busy looping, without ever trying to reconnect.
This patch adds a sleep and periodically tries to reconnect.
Also, it closes the socket when the setup of the connection fails.
There's still a bit of spamming during disconnected state: