From: Remi Gacogne Date: Thu, 11 Aug 2022 08:09:50 +0000 (+0200) Subject: dnsdist: Do not log on out-of-memory, but wait a bit before recovering X-Git-Tag: dnsdist-1.8.0-rc1~129^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b9e1dce758697024ba91d46f977a4e0112609d4;p=thirdparty%2Fpdns.git dnsdist: Do not log on out-of-memory, but wait a bit before recovering --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index fc21188fba..19005d2cfa 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1791,10 +1791,11 @@ static void udpClientThread(std::vector states) processUDPQuery(*param.cs, holders, &msgh, remote, dest, packet, nullptr, nullptr, nullptr, nullptr); } - catch (const std::exception& e) { + catch (const std::bad_alloc& e) { /* most exceptions are handled by processUDPQuery(), but we might be out of memory (std::bad_alloc) - in which case we want to try to recover */ - warnlog("Exception while processing an incoming UDP packet: %s", e.what()); + in which case we DO NOT want to log (as it would trigger another memory allocation attempt + that might throw as well) but wait a bit (one millisecond) and then try to recover */ + usleep(1000); } }; @@ -1825,10 +1826,11 @@ static void udpClientThread(std::vector states) fillMSGHdr(&msgh, &iov, &cbuf, sizeof(cbuf), reinterpret_cast(&packet.at(0)), param->maxIncomingPacketSize, &remote); handleOnePacket(*param); } - catch (const std::exception& e) { + catch (const std::bad_alloc& e) { /* most exceptions are handled by handleOnePacket(), but we might be out of memory (std::bad_alloc) - in which case we want to try to recover */ - warnlog("Exception while processing an incoming UDP packet: %s", e.what()); + in which case we DO NOT want to log (as it would trigger another memory allocation attempt + that might throw as well) but wait a bit (one millisecond) and then try to recover */ + usleep(1000); } }; auto mplexer = std::unique_ptr(FDMultiplexer::getMultiplexerSilent());