Check if async connect() is success before read() or wirte() in TransportTCP #1202
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.
I found a bug in
transport_tcp.cpp
when I using ROS inWindows Subsystem for Linux (WSL)
.TransportTCP::read()
did not check if aync socket is conneted. If socket is asynchronous, it may fails at recv() if its slow to connect (e.g. happens with wireless).TransportTCP::read()
andTransportTCP::write()
needs to check if its connected or not if it's asynchronous.Detailed debug log
Test Environment:
Fix
I add function
is_async_connected()
toio.h
. Given a socket which is still async connecting, this function will check if the connection is success, failed or still processing.And I add a private member
async_connected_
to TransportTCP.Before every read() or write() on async socket, if async_connected_ is false, it will call
is_async_connected()
to check it. If it's connected,async_connected_
is set to true.Test
WSL and Ubuntu
I have tested this fix in my multi-machine project using the patched ros_comm (https://github.com/bxwllzz/ros_comm/tree/kinetic-fix-transport-tcp)
Only on Ubuntu
test_roscpp
I have also run unit_tests by running
catkin_make run_tests
in ros_comm package for both WSL and Ubuntu.catkin_test_results build/test_results/test_roscpp/
reports no failures.Maybe more tests about
is_async_connected()
is needed for native Windows. Becauseselect()
in WinSock is a little different from that in Unix. I have read documents about WinSock connect() select() and Unix connect() seriously to implementeis_async_connected()
.If other WSL users wants to try this fix for ROS Kinetic ahead, please clone my branch kinetic-fix-transport-tcp to your catkin workspace.