]> git.mxchange.org Git - flightgear.git/commitdiff
Prevent download of thousands of METAR reports if all are for some reason
authormfranz <mfranz>
Mon, 14 Nov 2005 17:18:27 +0000 (17:18 +0000)
committermfranz <mfranz>
Mon, 14 Nov 2005 17:18:27 +0000 (17:18 +0000)
too old (wrong system time or broken proxy): stops after 10 stale reports
were fetched in a row. This should simply stop further fetching, but due
to a bug in the threading system(?) it does currently lead to abortion,
just like any other exception in the fetcher.

src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx

index 5625cd666c94eef69bdb97ad36929f171cacea1c..814f1f4a33e1cdb3f884abc8468261bc8b2e798e 100644 (file)
@@ -326,6 +326,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
       proxy_auth( fgGetNode("/sim/presets/proxy/authentication", true) ),
       metar_max_age( fgGetNode("/environment/params/metar-max-age-min", true) ),
       _error_count( 0 ),
+      _stale_count( 0 ),
       _dt( 0.0 ),
       _error_dt( 0.0 )
 {
@@ -399,7 +400,7 @@ FGMetarEnvironmentCtrl::init ()
     // Don't check max age during init so that we don't loop over a lot
     // of airports metar if there is a problem.
     // The update() calls will find a correct metar if things went wrong here
-    metar_max_age->setLongValue(60 * 24 * 7);
+    metar_max_age->setLongValue(0);
 
     while ( !found_metar && (_error_count < 3) ) {
         const FGAirport* a = globals->get_airports()
@@ -564,11 +565,18 @@ FGMetarEnvironmentCtrl::fetch_data( const string &icao )
         result.m = new FGMetar( icao, host, port, auth);
 
         long max_age = metar_max_age->getLongValue();
-        if (max_age && result.m->getAge_min() > max_age) {
-            SG_LOG( SG_GENERAL, SG_WARN, "METAR data too old");
+        long age = result.m->getAge_min();
+        if (max_age &&  age > max_age) {
+            SG_LOG( SG_GENERAL, SG_WARN, "METAR data too old (" << age << " min).");
             delete result.m;
             result.m = NULL;
-        }
+
+            if (++_stale_count > 10) {
+                _error_count = 1000;
+                throw sg_io_exception("More than 10 stale METAR messages in a row.");
+            }
+        } else
+            _stale_count = 0;
 
     } catch (const sg_io_exception& e) {
         SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
index 61efc075668981e7b6f9f90cca80bc0bb07125bc..be009962e8e5163e2125b1b31d3a011c1bbb27ae 100644 (file)
@@ -254,6 +254,7 @@ private:
 #endif // ENABLE_THREADS
 
     int _error_count;
+    int _stale_count;
     double _dt;
     double _error_dt;
 };