From 8d08486edf93269bdbd1eb4ef933c9cc5f6dd609 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 11 May 2022 11:36:57 +0200 Subject: [PATCH] refclock: restart local mode after losing lock A refclock in the local mode is locked to itself. When the maxlockage check failed after missing some samples, it failed permanently and the refclock was not able to accumulate any new samples. When the check fails, drop all samples and reset the source to start from scratch. Reported-by: Dan Drown --- refclock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/refclock.c b/refclock.c index 272777a..b59acc3 100644 --- a/refclock.c +++ b/refclock.c @@ -592,8 +592,14 @@ RCL_AddCookedPulse(RCL_Instance instance, struct timespec *cooked_time, sample_diff = UTI_DiffTimespecsToDouble(cooked_time, &ref_sample.time); if (fabs(sample_diff) >= (double)instance->max_lock_age / rate) { - DEBUG_LOG("refclock pulse ignored samplediff=%.9f", - sample_diff); + DEBUG_LOG("refclock pulse ignored samplediff=%.9f", sample_diff); + + /* Restart the local mode */ + if (instance->local) { + LOG(LOGS_WARN, "Local refclock lost lock"); + SPF_DropSamples(instance->filter); + SRC_ResetInstance(instance->source); + } return 0; }