Skip to content
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

ROS_IPV6 is checked too late in roscpp #1262

Closed
zielmicha opened this issue Dec 13, 2017 · 3 comments
Closed

ROS_IPV6 is checked too late in roscpp #1262

zielmicha opened this issue Dec 13, 2017 · 3 comments

Comments

@zielmicha
Copy link
Contributor

ROS_IPV6 environment variable is checked late in initialization process (in ros::start):

env_ipv6 = getenv("ROS_IPV6"); //...
bool use_ipv6 = (env_ipv6 && strcmp(env_ipv6,"on") == 0); //...
XmlRpc::XmlRpcSocket::s_use_ipv6_ = use_ipv6;

However, first connection to master can be initialized as early as in ros::init - failing the whole process and preventing nodes from starting.

If I change default value of XmlRpc::XmlRpcSocket::s_use_ipv6_ to true manually, these nodes work in IPv6 environment. The correct solution would be to move ROS_IPV6 check to the beginning of ros::init.

@dirk-thomas
Copy link
Member

Can you please provide a reproducible example. It would be great if you could consider to create a pull request for addressing this too.

@zielmicha
Copy link
Contributor Author

zielmicha commented Dec 15, 2017

  1. Run roscore on machine A with ROS_IPV6=on.
  2. Run rviz on machine B (with ROS_MASTER_URI set to machine A and ROS_IPV6=on). Observe that rviz can't connect to master.

Note: there must be no working IPv4 connectivity between these machines.

Here is a patch that fixes this problem - I'm not sure which branch I should submit PR to:

diff --git a/clients/roscpp/src/libros/init.cpp b/clients/roscpp/src/libros/init.cpp
index 91e0a58..7a38aaa 100644
--- a/clients/roscpp/src/libros/init.cpp
+++ b/clients/roscpp/src/libros/init.cpp
@@ -316,17 +316,6 @@ void start()
     }
   }
 
-  char* env_ipv6 = NULL;
-#ifdef _MSC_VER
-  _dupenv_s(&env_ipv6, NULL, "ROS_IPV6");
-#else
-  env_ipv6 = getenv("ROS_IPV6");
-#endif
-
-  bool use_ipv6 = (env_ipv6 && strcmp(env_ipv6,"on") == 0);
-  TransportTCP::s_use_ipv6_ = use_ipv6;
-  XmlRpc::XmlRpcSocket::s_use_ipv6_ = use_ipv6;
-
 #ifdef _MSC_VER
   if (env_ipv6)
   {
@@ -430,6 +419,19 @@ end:
   }
 }
 
+void check_ipv6_environment() {
+  char* env_ipv6 = NULL;
+#ifdef _MSC_VER
+  _dupenv_s(&env_ipv6, NULL, "ROS_IPV6");
+#else
+  env_ipv6 = getenv("ROS_IPV6");
+#endif
+
+  bool use_ipv6 = (env_ipv6 && strcmp(env_ipv6,"on") == 0);
+  TransportTCP::s_use_ipv6_ = use_ipv6;
+  XmlRpc::XmlRpcSocket::s_use_ipv6_ = use_ipv6;
+}
+
 void init(const M_string& remappings, const std::string& name, uint32_t options)
 {
   if (!g_atexit_registered)
@@ -453,6 +455,7 @@ void init(const M_string& remappings, const std::string& name, uint32_t options)
 #ifndef WIN32
     signal(SIGPIPE, SIG_IGN);
 #endif
+    check_ipv6_environment();
     network::init(remappings);
     master::init(remappings);
     // names:: namespace is initialized by this_node

@dirk-thomas
Copy link
Member

I'm not sure which branch I should submit PR to

Please create a pull request against the default branch (currently lunar-devel).

zielmicha added a commit to zielmicha/ros_comm that referenced this issue Dec 15, 2017
ROS_IPV6 environment variable was checked after first connection could be established.
This commit moves this check into early initialization.
dirk-thomas pushed a commit that referenced this issue Feb 9, 2018
ROS_IPV6 environment variable was checked after first connection could be established.
This commit moves this check into early initialization.
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

No branches or pull requests

2 participants