]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: allow logging one selection failure on start
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 29 Apr 2024 14:00:58 +0000 (16:00 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 2 May 2024 10:51:38 +0000 (12:51 +0200)
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.

sources.c
test/simulation/118-maxdelay
test/simulation/119-smoothtime
test/simulation/122-xleave
test/simulation/126-burst
test/simulation/127-filter
test/simulation/144-monoroot

index 626aaa5b6b98855ba1ffdf11b525fcb2fd835738..261444845e4568eb1b320907a98c1fa37a288dc9 100644 (file)
--- 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);
index 117b170b874b80159cd2aa17f8bfd9bfc24d7275..8ab0a62f76c7b14462faff0154c366471bff31f2 100755 (executable)
@@ -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
 
index 7f5114c80d26afb104d33d00d06593d1ae933403..fc2c6be9d2511b0cdf83b1175a2a37befce9a489 100755 (executable)
@@ -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
index c19063a5363eb369563872d1141778b3e7d0c0cc..77059d8ce24ec2dd8ee38c51d4016a14f5394c85 100755 (executable)
@@ -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
index 1cb6f9c7444e5c6b890ac579cc619bfcbe06a27f..baae3d529964f4c929ba2614b49b61c37fe04434 100755 (executable)
@@ -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
 
index 739dd9156fe695239cbbce8887327ab8eee9d0d2..68afec2750fa3991d31f474d909ca12306b7c3f2 100755 (executable)
@@ -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
 
index 20fae12b0cd7055a389109b10ed7fb3ab95a79e7..d97f30d18cf6731c2ef32964e8bae220d5de4170 100755 (executable)
@@ -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