WSL: Subscribing & Publishing from ROS nodes does not work

The current state of WSL makes working with ROS nodes on WSL impossible.

What works

What doesn’t work

  • Already something simple as rostopic echo /rosout fails with the message

[WARN] [1479567965.827686]: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.

It seems that the implementation of network sockets on WSL is still incomplete.

I tested this on builds 14965 and 14971.

More information

To help prioritize this issue, I created a post on User Voice

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 38 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Just tested this and it seems to work. I’m not entirely sure about commenting that ROS_ASSERT(..) though.

See gavanderhoorn/ros_comm@c83508d for the diff.

Nice work @bxwllzz 👍.

Would be nice if you could submit a PR against ros_comm to get this merged into mainline.

I have determined the problem. The problem lies in the ROS. Line 316 in ros_comm/roscpp/src/libros/transport/transport_tcp.cpp

  211 
  212 bool TransportTCP::connect(const std::string& host, int port)
  213 {
  214   if (!isHostAllowed(host))
  215     return false; // adios amigo
  216 
  217   sock_ = socket(s_use_ipv6_ ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
  218   connected_host_ = host;
  219   connected_port_ = port;
  220 
  221   if (sock_ == ROS_INVALID_SOCKET)
  222   {
  223     ROS_ERROR("socket() failed with error [%s]",  last_socket_error_string());
  224     return false;
  225   }
  226 
  227   setNonBlocking();
  228 
  229   sockaddr_storage sas;
  230   socklen_t sas_len;

         ... resolve host ...

  312   int ret = ::connect(sock_, (sockaddr*) &sas, sas_len);
  313   // windows might need some time to sleep (input from service robotics hack) add this if testing proves it is necessary.
  314   ROS_ASSERT((flags_ & SYNCHRONOUS) || ret != 0);
  315   if (((flags_ & SYNCHRONOUS) && ret != 0) || // synchronous, connect() should return 0
  316       (!(flags_ & SYNCHRONOUS) && last_socket_error() != ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN)) // asynchronous, connect() should return -1 and WSAGetLastError()=WSAEWOULDBLOCK/errno=EINPROGRESS
  317   {
  318     ROSCPP_CONN_LOG_DEBUG("Connect to tcpros publisher [%s:%d] failed with error [%d, %s]", host.c_str(), port, ret, last_socket_error_string());
  319     close();
  320 
  321     return false;
  322   }
  323 

It assumes that the connect method of non-blocking scoket should return -1 and last_socket_error() should return ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN(=EINPROGRESS). But a non-blocking connect can return 0 when TCP connection to 127.0.0.1 (localhost). http://stackoverflow.com/questions/14027326/can-connect-return-0-with-non-blocing-socket

Hi there! I have just apt-installed ros kinetic on WSL Ubuntu 16.04. The python talker/listener example only works as long as I start both from the same bash. Is that still the issue here? Wasn’t it fixed in October 2017?

A bit more on the symptoms: I can run a roscore in one bash window, then in another I execute

rosrun rospy_tutorial talker.py & rosrun rospy_tutorial listener.py

or

rosrun rospy_tutorial talker.py & rostopic echo /chatter

and everything works as expected. When I run rostopic list from another bash window, it also shows the /chatter topic but neither listener.py nor rostopic echo receive anything.

Any help appreciated!

FYI : As of today, ROS kinetic (ros_comm 1.12.7) work out of box on WSL 16299.19, without changing source tree.

https://answers.ros.org/question/238646/installing-ros-on-ubuntu-bash-in-windows-10/

I have submit a PR to ros_comm https://github.com/ros/ros_comm/pull/1050

Replace

  312   int ret = ::connect(sock_, (sockaddr*) &sas, sas_len);
  313   // windows might need some time to sleep (input from service robotics hack) add this if testing proves it is necessary.
  314   ROS_ASSERT((flags_ & SYNCHRONOUS) || ret != 0);
  315   if (((flags_ & SYNCHRONOUS) && ret != 0) || // synchronous, connect() should return 0
  316       (!(flags_ & SYNCHRONOUS) && last_socket_error() != ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN)) // asynchronous, connect() should return -1 and WSAGetLastError()=WSAEWOULDBLOCK/errno=EINPROGRESS
  317   {
  318     ROSCPP_CONN_LOG_DEBUG("Connect to tcpros publisher [%s:%d] failed with error [%d, %s]", host.c_str(), port, ret, last_socket_error_string());
  319     close();
  320 
  321     return false;
  322   }

in ros_comm/roscpp/src/libros/transport/transport_tcp.cpp with

  int ret = ::connect(sock_, (sockaddr*) &sas, sas_len);
  // windows might need some time to sleep (input from service robotics hack) add this if testing proves it is necessary.
  // ROS_ASSERT((flags_ & SYNCHRONOUS) || ret != 0);
  if (((flags_ & SYNCHRONOUS) && ret != 0) || // synchronous, connect() should return 0
      (!(flags_ & SYNCHRONOUS) && // asynchronous, connect() may return 0 or -1. When return 0, WSAGetLastError()=WSAEWOULDBLOCK/errno=EINPROGRESS
      (ret != 0 && last_socket_error() != ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN))) 
  {
    ROSCPP_CONN_LOG_DEBUG("Connect to tcpros publisher [%s:%d] failed with error [%d, %s]", host.c_str(), port, ret, last_socket_error_string());
    close();

    return false;
  }

TOPIC of ROS works. Test success in ROS/Tutorials/WritingPublisherSubscriber(python), ROS/Tutorials/ExaminingPublisherSubscriber and turtlesim

Easiest is probably to use an overlay workspace with just ros_comm checked out and built from sources.

The issue persists in 15048

$ rostopic echo /rosout
[WARN] [1489011779.094188]: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.
header:
  seq: 1
  stamp:
    secs: 1489011779
    nsecs:  95611095
  frame_id: ''
level: 4
name: /rostopic_113_1489011778600
msg: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.
file: tcpros_base.py
function: _tcp_server_callback
line: 351
topics: ['/rosout']
---