[Lldb-commits] [PATCH] D58131: [lldb] [unittest] Avoid mixing '127.0.0.1' and 'localhost'

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 12 08:42:22 PST 2019


mgorny created this revision.
mgorny added reviewers: k8stone, labath, krytarowski.
mgorny added a project: LLDB.

Fix the tests not to use '127.0.0.1' and 'localhost' interchangeably.
More specifically, since tests bind specifically to 127.0.0.1, connect
to that address as well; using 'localhost' can resolve to IPv6 address
which can cause issues -- for example, if the matching port happens to
be used by some other process, the tests hang forever waiting for
the client to connect.

While technically the case of randomly selected IPv4 port being taken
on IPv6 loopback is not very likely, NetBSD happens to be suffering from
some weird kernel issue where connection to that port succeeds
nevertheless.  Until we can really figure out what goes wrong there,
this saves us from the tests hanging randomly.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D58131

Files:
  lldb/unittests/Host/SocketTest.cpp
  lldb/unittests/tools/lldb-server/tests/TestClient.cpp


Index: lldb/unittests/tools/lldb-server/tests/TestClient.cpp
===================================================================
--- lldb/unittests/tools/lldb-server/tests/TestClient.cpp
+++ lldb/unittests/tools/lldb-server/tests/TestClient.cpp
@@ -80,7 +80,7 @@
     return status.ToError();
 
   args.AppendArgument(
-      ("localhost:" + Twine(listen_socket.GetLocalPortNumber())).str());
+      ("127.0.0.1:" + Twine(listen_socket.GetLocalPortNumber())).str());
 
   for (StringRef arg : ServerArgs)
     args.AppendArgument(arg);
Index: lldb/unittests/Host/SocketTest.cpp
===================================================================
--- lldb/unittests/Host/SocketTest.cpp
+++ lldb/unittests/Host/SocketTest.cpp
@@ -179,7 +179,7 @@
       [=](const TCPSocket &s) {
         char connect_remote_address[64];
         snprintf(connect_remote_address, sizeof(connect_remote_address),
-                 "localhost:%u", s.GetLocalPortNumber());
+                 "127.0.0.1:%u", s.GetLocalPortNumber());
         return std::string(connect_remote_address);
       },
       &socket_a_up, &socket_b_up);
@@ -193,7 +193,7 @@
       [=](const TCPSocket &s) {
         char connect_remote_address[64];
         snprintf(connect_remote_address, sizeof(connect_remote_address),
-                 "localhost:%u", s.GetLocalPortNumber());
+                 "127.0.0.1:%u", s.GetLocalPortNumber());
         return std::string(connect_remote_address);
       },
       &socket_a_up, &socket_b_up);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58131.186484.patch
Type: text/x-patch
Size: 1496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190212/dbb471d4/attachment-0001.bin>


More information about the lldb-commits mailing list