]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Better exception handling in houseKeeping
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Jun 2020 13:07:08 +0000 (15:07 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Jun 2020 13:15:54 +0000 (15:15 +0200)
An uncaugth exception being raised in houseKeeping could prevent it
from being run again because 's_running' would stay true. That could
for example happen when an ImmediateServFailException was raised during
a call to primeRootNSZones().

pdns/pdns_recursor.cc

index cd336817df5128cb7af4d0fae62b1445e00d386f..a13434dcfc9005bb9dbd0df40875f7455a57db15 100644 (file)
@@ -3187,7 +3187,25 @@ static void houseKeeping(void *)
         int res = SyncRes::getRootNS(g_now, nullptr, 0);
         if (!res) {
           last_rootupdate=now.tv_sec;
-          primeRootNSZones(g_dnssecmode != DNSSECMode::Off, 0);
+          try {
+            primeRootNSZones(g_dnssecmode != DNSSECMode::Off, 0);
+          }
+          catch (const std::exception& e) {
+            g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.what()<<endl;
+          }
+          catch (const PDNSException& e) {
+            g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.reason<<endl;
+          }
+          catch (const ImmediateServFailException& e) {
+            g_log<<Logger::Error<<"Exception while priming the root NS zones: "<<e.reason<<endl;
+          }
+          catch (const PolicyHitException& e) {
+            g_log<<Logger::Error<<"Policy hit while priming the root NS zones"<<endl;
+          }
+          catch (...)
+          {
+            g_log<<Logger::Error<<"Exception while priming the root NS zones"<<endl;
+          }
         }
       }
 
@@ -3195,22 +3213,22 @@ static void houseKeeping(void *)
        try {
          doSecPoll(&last_secpoll);
        }
-       catch(const std::exception& e)
+       catch (const std::exception& e)
         {
           g_log<<Logger::Error<<"Exception while performing security poll: "<<e.what()<<endl;
         }
-        catch(const PDNSException& e)
+        catch (const PDNSException& e)
         {
           g_log<<Logger::Error<<"Exception while performing security poll: "<<e.reason<<endl;
         }
-        catch(const ImmediateServFailException &e)
+        catch (const ImmediateServFailException &e)
         {
           g_log<<Logger::Error<<"Exception while performing security poll: "<<e.reason<<endl;
         }
-        catch(const PolicyHitException& e) {
+        catch (const PolicyHitException& e) {
           g_log<<Logger::Error<<"Policy hit while performing security poll"<<endl;
         }
-        catch(...)
+        catch (...)
         {
           g_log<<Logger::Error<<"Exception while performing security poll"<<endl;
         }
@@ -3232,14 +3250,20 @@ static void houseKeeping(void *)
         }
       }
     }
-    s_running=false;
+    s_running = false;
+  }
+  catch (const PDNSException& ae)
+  {
+    s_running = false;
+    g_log<<Logger::Error<<"Fatal error in housekeeping thread: "<<ae.reason<<endl;
+    throw;
+  }
+  catch (...)
+  {
+    s_running = false;
+    g_log<<Logger::Error<<"Uncaught exception in housekeeping thread"<<endl;
+    throw;
   }
-  catch(PDNSException& ae)
-    {
-      s_running=false;
-      g_log<<Logger::Error<<"Fatal error in housekeeping thread: "<<ae.reason<<endl;
-      throw;
-    }
 }
 
 static void makeThreadPipes()