From 6a3be655d2bc808b7038d8a84bd3ae9589cebb1b Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 14 Nov 2005 17:18:27 +0000 Subject: [PATCH] Prevent download of thousands of METAR reports if all are for some reason 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 | 16 ++++++++++++---- src/Environment/environment_ctrl.hxx | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index 5625cd666..814f1f4a3 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -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: " diff --git a/src/Environment/environment_ctrl.hxx b/src/Environment/environment_ctrl.hxx index 61efc0756..be009962e 100644 --- a/src/Environment/environment_ctrl.hxx +++ b/src/Environment/environment_ctrl.hxx @@ -254,6 +254,7 @@ private: #endif // ENABLE_THREADS int _error_count; + int _stale_count; double _dt; double _error_dt; }; -- 2.39.5