MobileNativeFoundation / MobileNativeFoundation/Kronos

Clock.sync() sometimes responses with no TimeInterval

Open
#118 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
699
Forks
100
PR merge metrics
No merged PRs in 30d

Description

I sometimes have problems with Clock.sync() not returning a TimeInterval in the completion closure. After an analysis I found out that the problem lies in the NTPClient in private func offset(from responses: [[NTPPacket]]) throws -> TimeInterval. All server responses are filtered here by originTime (which is afaik ok). Now it can happen that certain responses take longer than 10 seconds (= kMaximumResultDispersion), especially if I use the default NTP server(s) time.apple.com with the default 4 samples. If this happens with the last response, no TimeInterval is returned. Although validate timeIntervals might have been returned beforehand. Is this done on purpose or would it also be possible to save the offsets in the sync() function (Clock.swift) and then return an average value at the end?

If I use the first closure I always get a valid offset (maybe there are cases where this response is also filtered).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Clock.swift at sync() and NTPClient at private func offset(from responses: [[NTPPacket]]) throws -> TimeInterval. Trace how originTime filtering and kMaximumResultDispersion affect the completion closure, comparing the behavior with the first closure. Done means the sync result remains valid when a late final response is filtered, with the intended averaging behavior established and covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.