Open zoranbosnjak opened 3 days ago
As such, "unsynchronized" is an expected state and the calling code should always account for it, especially at the beginning, when the NTP client latches on. But the randomization could easily be parametrized. And a couple of other things could be parametrized to tweak the NTP client logic, too.
Communication errors encountered during querying are an expected case and should trigger some back off logic in polling intervals (that's at least my understanding of RFC). That's why query_peers
always returns a pause to the next poll, if it didn't then caller would need to bring in its own logic. I would keep this level of abstraction of query_peers
because it is very convenient if you just want to follow the intended use case. But it could be broken down to allow for more granular control.
It's true that communication errors are to be expected. But I don't think this reasoning is justified here. I this particular scenario, there was no real error, so the calling code should get clean status. At least I my usecase I would like to avoid false alarms as much as possible.
Anyway, additional parametrization is indeed an easy fix. See pull request.
Test program from the README example often fails during the first loop iterration. It looks like this is the unfortunate consequence of randomization during
NtpAssociation
init. The comment explains a reason for this (to avoid bursts). The problem is that it can generate false alarms during program startup, where I am actually checking the offsets. I am looking for a way to workaround it.One obvious candidate is the the
query_peers
method, which currently returns plainfloat
- pause time or zero in some cases. This makes it impossible for the user to check the success, based on the return value. Please consider changing return type toOptional[float]
and returnNone
in cases where the method did not make any progress. The handling on the call site would also require minor update.Not sure if a better solution would be to restrict the randomness during init, such that it remains in the safe interval.
This is the example program with debugging enabled:
Results (sometimes) in: