Skip to content

Commit

Permalink
HPCC-31990 Add timeout to DNS lookups for soapcalls using a threadpool 3
Browse files Browse the repository at this point in the history
Signed-off-by: M Kelly <[email protected]>
  • Loading branch information
mckellyln committed Jul 23, 2024
1 parent 2c2cd62 commit 94f5195
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,12 @@ static bool getAddressInfo(const char *name, unsigned *netaddr, bool okToLogErr)

static CriticalSection queryDNSCS;

class CAddrInfoThreadArgs : public CInterface, implements IInterface
class CAddrInfoThreadArgs : public CInterface
{
public:
IMPLEMENT_IINTERFACE;
StringAttr name;
unsigned netaddr[4] = { 0, 0, 0, 0 };
bool result = false;
std::atomic<bool> result { false };

CAddrInfoThreadArgs(const char *_name) : name(_name) { }
};
Expand Down Expand Up @@ -529,19 +528,21 @@ class CAddrInfoFactory : public CInterface, public IThreadFactory

static Owned<CAddrInfoFactory> addrInfoFactory;
static Owned<IThreadPool> addrInfoPool;
static std::atomic<bool> addrInfoPoolCreated { false };

static bool useDNSTimeout()
{
queryTCPSettings();
if (!disableDNSTimeout)
{
if (!addrInfoPool)
if (!addrInfoPoolCreated.load())
{
CriticalBlock block(queryDNSCS);
if (!addrInfoPool)
if (!addrInfoPoolCreated.load())
{
addrInfoFactory.setown(new CAddrInfoFactory);
addrInfoPool.setown(createThreadPool("AddrInfoPool", addrInfoFactory, true, nullptr, maxDNSThreads, 100000000));
addrInfoPoolCreated = true;
}
}
return true;
Expand All @@ -558,10 +559,11 @@ MODULE_EXIT()
{
// NB: this (and other MODULE_EXITs) are not called for Thor and Roxie because they are
// stopped via SIGTERM signal and thus exit() and the atexit handlers are not called
if (addrInfoPool)
if (addrInfoPoolCreated.load())
{
addrInfoPool->joinAll(true);
addrInfoPool.clear();
addrInfoPoolCreated = false;
}
}

Expand Down Expand Up @@ -3417,7 +3419,7 @@ static bool decodeNumericIP(const char *text,unsigned *netaddr)

static void RecursionSafeLogErr(int ret, int ref, const char *msg, unsigned lineno, const char *name)
{
static bool recursioncheck = false; // needed to stop error message recursing
static __thread bool recursioncheck = false; // needed to stop error message recursing
if (!recursioncheck)
{
recursioncheck = true;
Expand Down Expand Up @@ -3451,6 +3453,7 @@ bool getAddressInfo(const char *name, unsigned *netaddr, bool okToLogErr)
Sleep((10-retry)*100);
else
{
// use gai_strerror(ret) to get meaningful error text ?
if (okToLogErr)
RecursionSafeLogErr(ret, 1, "getaddrinfo failed", __LINE__, name);
return false;
Expand Down

0 comments on commit 94f5195

Please sign in to comment.