[Lldb-commits] [lldb] r353868 - [lldb] [unittest] Avoid mixing '127.0.0.1' and 'localhost'

Michal Gorny via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 12 10:09:00 PST 2019


Author: mgorny
Date: Tue Feb 12 10:09:00 2019
New Revision: 353868

URL: http://llvm.org/viewvc/llvm-project?rev=353868&view=rev
Log:
[lldb] [unittest] Avoid mixing '127.0.0.1' and 'localhost'

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.

Differential Revision: https://reviews.llvm.org/D58131

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

Modified: lldb/trunk/unittests/Host/SocketTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/SocketTest.cpp?rev=353868&r1=353867&r2=353868&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/SocketTest.cpp (original)
+++ lldb/trunk/unittests/Host/SocketTest.cpp Tue Feb 12 10:09:00 2019
@@ -179,7 +179,7 @@ TEST_F(SocketTest, TCPListen0ConnectAcce
       [=](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 @@ TEST_F(SocketTest, TCPGetAddress) {
       [=](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);

Modified: lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp?rev=353868&r1=353867&r2=353868&view=diff
==============================================================================
--- lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp (original)
+++ lldb/trunk/unittests/tools/lldb-server/tests/TestClient.cpp Tue Feb 12 10:09:00 2019
@@ -80,7 +80,7 @@ Expected<std::unique_ptr<TestClient>> Te
     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);




More information about the lldb-commits mailing list