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 cecee50308.
This commit is contained in:
max ulidtko authored and Jens Geyer committed 2020-05-08 09:23:47 +02:00
1 parent bbc5e06a2e
commit 9b9567b233
5 files changed
+10 -6

No files matched your search

@@ -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);
@@ -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);
+6 -2
View File
@@ -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()
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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: