Jens Geyer created THRIFT-6226:
----------------------------------

             Summary: C++: TServerSocket::listen() tries only the first 
resolved address unless a retry limit is set
                 Key: THRIFT-6226
                 URL: https://issues.apache.org/jira/browse/THRIFT-6226
             Project: Thrift
          Issue Type: Bug
          Components: C++ - Library
            Reporter: Jens Geyer


The TCP bind loop in {{TServerSocket::listen()}} ({{TServerSocket.cpp}}, lines 
508-545 on master) is commented "we iterate over what system gave us, picking 
the first address that works", but it ends with

{code:cpp}
} while ((retries++ < retryLimit_) && (THRIFT_SLEEP_SEC(retryDelay_) == 0));
{code}

and {{retryLimit_}} is 0 after every constructor. When the first address fails 
to bind, the loop ends, and the next address is never tried unless the caller 
has used {{setRetryLimit()}}. A {{socket()}} failure on the first address -- 
{{AF_INET6}} on a host without IPv6, say -- ends it the same way, because 
{{continue}} in a {{do ... while}} jumps straight to that condition.

So a host name that resolves to more than one address fails to listen whenever 
the first one cannot be used, even if a later one would work. Found while 
looking at THRIFT-6191.

Suggested fix: try every resolved address in each attempt, and apply the retry 
limit to whole passes over the list.

_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to