]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Do not log on out-of-memory, but wait a bit before recovering
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 11 Aug 2022 08:09:50 +0000 (10:09 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 16 Dec 2022 10:56:01 +0000 (11:56 +0100)
pdns/dnsdist.cc

index fc21188fba1eda234d49d46654caecad3043c0cf..19005d2cfaa528295eb6fe5b35e2a91e8ea7355a 100644 (file)
@@ -1791,10 +1791,11 @@ static void udpClientThread(std::vector<ClientState*> 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<ClientState*> states)
             fillMSGHdr(&msgh, &iov, &cbuf, sizeof(cbuf), reinterpret_cast<char*>(&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>(FDMultiplexer::getMultiplexerSilent());