From: Miroslav Lichvar Date: Mon, 29 Apr 2024 14:00:58 +0000 (+0200) Subject: sources: allow logging one selection failure on start X-Git-Tag: 4.6-pre1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d6c7a527db16cda1639b13ed47e127571dff55;p=thirdparty%2Fchrony.git sources: allow logging one selection failure on start Allow one message about failed selection (e.g. no selectable sources) to be logged before first successful selection when a source has full-size reachability register (8 polls with a received or missed response). This should make it more obvious that chronyd has a wrong configuration or there is a firewall/networking issue. --- diff --git a/sources.c b/sources.c index 626aaa5b..26144484 100644 --- a/sources.c +++ b/sources.c @@ -177,6 +177,8 @@ static int reported_no_majority; /* Flag to avoid repeated log message static int report_selection_loss; /* Flag to force logging a message if selection is lost in a transient state (SRC_WAITS_STATS, SRC_WAITS_UPDATE) */ +static int forced_first_report; /* Flag to allow one failed selection to be + logged before a successful selection */ /* Score needed to replace the currently selected source */ #define SCORE_LIMIT 10.0 @@ -862,7 +864,8 @@ SRC_SelectSource(SRC_Instance updated_inst) struct SelectInfo *si; struct timespec now, ref_time; int i, j, j1, j2, index, sel_prefer, n_endpoints, n_sel_sources, sel_req_source; - int n_badstats_sources, max_sel_reach, max_sel_reach_size, max_badstat_reach; + int max_badstat_reach, max_badstat_reach_size, n_badstats_sources; + int max_sel_reach, max_sel_reach_size; int depth, best_depth, trust_depth, best_trust_depth, n_sel_trust_sources; int combined, stratum, min_stratum, max_score_index; int orphan_stratum, orphan_source; @@ -893,7 +896,7 @@ SRC_SelectSource(SRC_Instance updated_inst) n_badstats_sources = 0; sel_req_source = 0; max_sel_reach = max_badstat_reach = 0; - max_sel_reach_size = 0; + max_sel_reach_size = max_badstat_reach_size = 0; max_reach_sample_ago = 0.0; for (i = 0; i < n_sources; i++) { @@ -924,6 +927,8 @@ SRC_SelectSource(SRC_Instance updated_inst) mark_source(sources[i], SRC_BAD_STATS); if (max_badstat_reach < sources[i]->reachability) max_badstat_reach = sources[i]->reachability; + if (max_badstat_reach_size < sources[i]->reachability_size) + max_badstat_reach_size = sources[i]->reachability_size; continue; } @@ -1068,6 +1073,14 @@ SRC_SelectSource(SRC_Instance updated_inst) return; } + /* Wait for a source to have full reachability register to allow one + failed selection to be logged before first successful selection */ + if (!forced_first_report && + MAX(max_sel_reach_size, max_badstat_reach_size) == SOURCE_REACH_BITS) { + report_selection_loss = 1; + forced_first_report = 1; + } + if (n_endpoints == 0) { /* No sources provided valid endpoints */ unselect_selected_source(LOGS_INFO, "Can't synchronise: no selectable sources", NULL); @@ -1334,6 +1347,7 @@ SRC_SelectSource(SRC_Instance updated_inst) reported_no_majority = 0; report_selection_loss = 0; + forced_first_report = 1; } mark_source(sources[selected_source_index], SRC_SELECTED); diff --git a/test/simulation/118-maxdelay b/test/simulation/118-maxdelay index 117b170b..8ab0a62f 100755 --- a/test/simulation/118-maxdelay +++ b/test/simulation/118-maxdelay @@ -14,7 +14,6 @@ client_server_options="maxpoll 6 maxdelay 3e-5 maxdelayratio 2.0 maxdelaydevrati run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/119-smoothtime b/test/simulation/119-smoothtime index 7f5114c8..fc2c6be9 100755 --- a/test/simulation/119-smoothtime +++ b/test/simulation/119-smoothtime @@ -14,7 +14,7 @@ max_sync_time=800 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_sync || test_fail limit=10000 diff --git a/test/simulation/122-xleave b/test/simulation/122-xleave index c19063a5..77059d8c 100755 --- a/test/simulation/122-xleave +++ b/test/simulation/122-xleave @@ -53,7 +53,6 @@ for rpoll in 4 5 6; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail check_sync || test_fail if [ $rpoll -le 5 ]; then diff --git a/test/simulation/126-burst b/test/simulation/126-burst index 1cb6f9c7..baae3d52 100755 --- a/test/simulation/126-burst +++ b/test/simulation/126-burst @@ -22,7 +22,7 @@ client_min_mean_out_interval=150.0 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/127-filter b/test/simulation/127-filter index 739dd915..68afec27 100755 --- a/test/simulation/127-filter +++ b/test/simulation/127-filter @@ -12,7 +12,7 @@ client_min_mean_out_interval=15.9 run_test || test_fail check_chronyd_exit || test_fail -check_source_selection || test_fail +check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail diff --git a/test/simulation/144-monoroot b/test/simulation/144-monoroot index 20fae12b..d97f30d1 100755 --- a/test/simulation/144-monoroot +++ b/test/simulation/144-monoroot @@ -20,7 +20,7 @@ for options in "extfield F323" "xleave extfield F323"; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done @@ -47,7 +47,7 @@ for lpoll in 5 6 7; do run_test || test_fail check_chronyd_exit || test_fail - check_source_selection || test_fail + check_source_selection && test_fail check_sync || test_fail done done