This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b9567b  THRIFT-5186: Don't pass AI_ADDRCONFIG to getaddrinfo() 
Client: cpp,pas,py Patch: Max Ulidtko
9b9567b is described below

commit 9b9567b23378c821b460cfe54b70b9d189bf194d
Author: max ulidtko <[email protected]>
AuthorDate: Mon Apr 27 16:04:27 2020 +0300

    THRIFT-5186: Don't pass AI_ADDRCONFIG to getaddrinfo()
    Client: cpp,pas,py
    Patch: Max Ulidtko
    
    This closes #2124
    
    If a host doesn't have assigned IPv4 or IPv6 addresses, thrift communication
    over localhost-only is impossible due to thrift library bug. It happens
    when making getaddrinfo syscall with AI_ADDRCONFIG flag.
    
    From man getaddrinfo(3):
    If  hints.ai_flags  includes  the  AI_ADDRCONFIG  flag,  then  IPv4  
addresses
    are returned in the list pointed to by res only if the local system has at 
least
    one IPv4 address configured, and IPv6 addresses are returned only if the 
local
    system has at least one IPv6 address configured.  The loopback address is 
not
    considered for this case as valid as a configured address.
    
    Upstream bug with AI_ADDRCONFIG ai_flags was fixed for cpp library and win32
    platform only. See https://issues.apache.org/jira/browse/THRIFT-2539
    
    Patch based on Thrift 0.13.0, commit 
cecee50308fc7e6f77f55b3fd906c1c6c471fa2f.
---
 lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp | 2 +-
 lib/cpp/src/thrift/transport/TServerSocket.cpp            | 2 +-
 lib/cpp/src/thrift/transport/TSocket.cpp                  | 8 ++++++--
 lib/delphi/src/Thrift.Socket.pas                          | 2 +-
 lib/py/src/transport/TSocket.py                           | 2 +-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp 
b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
index 9902b90..c50ce38 100644
--- a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
@@ -191,7 +191,7 @@ void TNonblockingServerSocket::listen() {
   std::memset(&hints, 0, sizeof(hints));
   hints.ai_family = PF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
-  hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+  hints.ai_flags = AI_PASSIVE;
 
   // If address is not specified use wildcard address (NULL)
   TGetAddrInfoWrapper info(address_.empty() ? nullptr : &address_[0], port, 
&hints);
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp 
b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index 662f6e5..150e530 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -270,7 +270,7 @@ void TServerSocket::listen() {
   std::memset(&hints, 0, sizeof(hints));
   hints.ai_family = PF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
-  hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+  hints.ai_flags = AI_PASSIVE;
 
   // If address is not specified use wildcard address (NULL)
   TGetAddrInfoWrapper info(address_.empty() ? nullptr : &address_[0], port, 
&hints);
diff --git a/lib/cpp/src/thrift/transport/TSocket.cpp 
b/lib/cpp/src/thrift/transport/TSocket.cpp
index 977834d..3811279 100644
--- a/lib/cpp/src/thrift/transport/TSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSocket.cpp
@@ -465,12 +465,16 @@ void TSocket::local_open() {
 
   error = getaddrinfo(host_.c_str(), port, &hints, &res0);
 
+  if (
 #ifdef _WIN32
-  if (error == WSANO_DATA) {
+      error == WSANO_DATA
+#else
+      error == EAI_NODATA
+#endif
+    ) {
     hints.ai_flags &= ~AI_ADDRCONFIG;
     error = getaddrinfo(host_.c_str(), port, &hints, &res0);
   }
-#endif
 
   if (error) {
     string errStr = "TSocket::open() getaddrinfo() " + getSocketInfo()
diff --git a/lib/delphi/src/Thrift.Socket.pas b/lib/delphi/src/Thrift.Socket.pas
index b33f202..01fdf36 100644
--- a/lib/delphi/src/Thrift.Socket.pas
+++ b/lib/delphi/src/Thrift.Socket.pas
@@ -575,7 +575,7 @@ begin
   FillChar(Hints, SizeOf(Hints), 0);
   Hints.ai_family := PF_UNSPEC;
   Hints.ai_socktype := SOCK_STREAM;
-  Hints.ai_flags := AI_PASSIVE or AI_ADDRCONFIG;
+  Hints.ai_flags := AI_PASSIVE;
   StrFmt(ThePort, '%d', [FPort]);
 
   Result := TGetAddrInfoWrapper.Create(AAddress, ThePort, @Hints);
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index df25d42..9886fa2 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -39,7 +39,7 @@ class TSocketBase(TTransportBase):
                                       self._socket_family,
                                       socket.SOCK_STREAM,
                                       0,
-                                      socket.AI_PASSIVE | socket.AI_ADDRCONFIG)
+                                      socket.AI_PASSIVE)
 
     def close(self):
         if self.handle:

Reply via email to