`Clock change detected. Flushing caches` and stop DNS to work in the WSL
Description
Hi! Pay attention to my comment and the issue itself, please https://github.com/microsoft/WSL/issues/13777#issuecomment-3646771107
Reproduce
Expected behavior
No response
docker version
-
docker info
-
Diagnostics ID
Additional Info
No response
Only when docker desktop is running, Clock change detected. Flushing caches message is generated every 30 seconds in the WSL syslog.
Mar 31 16:06:50 device systemd-resolved[171]: Clock change detected. Flushing caches.
Mar 31 16:06:21 device systemd-resolved[171]: Clock change detected. Flushing caches.
Mar 31 16:05:51 device systemd-resolved[171]: Clock change detected. Flushing caches.
Running Ubuntu 24.04 and Docker Desktop 4.67.0.
Adding the mechanism behind this symptom, traced on an affected box (Docker Desktop 4.77.0, engine 29.5.3; also observed by the reporter above on 4.67.0). Short version: the 30-second clock step is a userspace settimeofday(2) call made by Docker Desktop's own init process (/initd) inside the docker-desktop distro — not WSL's Hyper-V TimeSync path, and not a kernel bug. Because all of a user's WSL2 distros share one utility VM and one CLOCK_REALTIME, the step lands on every co-resident distro, which is why systemd-resolved in an unrelated Ubuntu distro flushes its DNS cache twice a minute.
1. Causation is reversible (A→B→A)
Counting clock steps with the same watcher systemd-resolved arms (timerfd + TFD_TIMER_CANCEL_ON_SET), toggling only Docker Desktop:
Docker Desktop UP 4 steps / 100 s @ 30.002 s (2.40/min)
Docker Desktop DOWN 0 steps / 130 s (0.00/min) <- DockerCli.exe -Shutdown
Docker Desktop UP 3 steps / 100 s @ 30.001 s (1.80/min) <- restarted
2. The transport is a userspace syscall from initd
bpftrace on the shared WSL2 kernel while the steps fired:
@host_disciplined_clock: 0 # hv_set_host_time (Hyper-V TimeSync path) — never called
@settimeofday_by[initd, 2801]: 3
@stack[
do_settimeofday64+5
__x64_sys_settimeofday+135 # <- plain settimeofday(2) from userspace
x64_sys_call+6775
do_syscall_64+90
entry_SYSCALL_64_after_hwframe+120
]: 3
[17:49:28] do_settimeofday64 <- comm=initd pid=2801
[17:49:58] do_settimeofday64 <- comm=initd pid=2801 # exactly 30 s apart
[17:50:28] do_settimeofday64 <- comm=initd pid=2801
The kernel Hyper-V TimeSync setter (hv_set_host_time, the function that would call do_settimeofday64 on a host-initiated sync) fired zero times — which also explains why hv_utils.timesync_implicit=0 does not help: the steps never enter that code path.
A follow-up capture joined each call to its argument and effect: five consecutive settimeofday(2) calls from comm=initd, each requesting a backward step (kernel-side capture of the timespec64 argument), each returning 0, each matched 1:1 with a TFD_TIMER_CANCEL_ON_SET cancellation — the per-event delta agreeing to microseconds with an independent realtime-vs-monotonic watcher, and hv_set_host_time again at zero throughout.
3. initd ships in Docker Desktop's distro, and nowhere else on this box
In the docker-desktop distro (PRETTY_NAME="Docker Desktop"), PID 1 is init(docker-desktop) and the processes with comm=initd resolve to the /initd binary. No initd exists in the affected Ubuntu distro (its init is systemd; the WSL core init is /init, comm init).
4. One VM, one clock
Both distros report the same boot_id and the same uptime — one utility VM, one CLOCK_REALTIME. A step made in the docker-desktop distro is a step in every distro.
5. Magnitude: ~1 ms
The steps measure at ~0.2–2.5 ms each (typically ~1.2–1.7 ms), always backward — two independent instruments (kernel-side capture of the requested timespec64 and userspace realtime-vs-monotonic differencing) agree per event to microseconds. These are tiny corrections applied as hard clock steps, every 30 s, for as long as Docker Desktop is running (observed across three days).
Suggested fix
Periodic guest-clock correction is legitimate (WSL2 guests genuinely drift across Windows sleep — cf. microsoft/WSL#10006). The problem is stepping rather than slewing:
- Slew small deltas via
adjtimex(gradualADJ_OFFSETslewing — notADJ_SETOFFSET, which is itself a step) instead ofsettimeofday. A slew is not aCLOCK_REALTIMEdiscontinuity and does not wakeTFD_TIMER_CANCEL_ON_SETwatchers — no cache flush, no log spam. This is exactly what the systemd maintainer prescribed when the consumer half of this was reported there (systemd/systemd#43028, closed not-our-bug: "if wsl makes continious small steps then they really should use the gradual clock changes (adjtimex) instead of the stepping ones (clock_settime)"). - Or gate on magnitude: only hard-step when the delta is large enough to matter (post-resume drift is seconds to minutes), and skip or slew when the guest is already within a few ms — as it was in every measurement here.
Either change stops the flush loop in every co-resident distro while keeping real post-resume corrections (a large step after actual sleep would still step, correctly).
Reproduction
# 1. Cadence (no root): arm an absolute CLOCK_REALTIME timerfd (TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET) and
# count ECANCELED wakeups — steps land every ~30 s while Docker Desktop runs.
# 2. Transport (root, bpftrace):
sudo bpftrace -e '
kprobe:hv_set_host_time { @host_path = count(); }
kprobe:do_settimeofday64 { @by[comm] = count(); @stk[kstack(5)] = count(); }
interval:s:95 { exit(); }'
# Expect: @host_path absent/0 ; @by[initd] > 0 ; stack through __x64_sys_settimeofday.
# 3. Causation: "DockerCli.exe -Shutdown" -> steps stop; restart Docker Desktop -> steps return.
Environment: Windows 10 (19045-class) host, WSL2 kernel 6.6.114.1-microsoft-standard-WSL2, Ubuntu 24.04 (systemd 255.4) co-resident with docker-desktop; reproduced 2026-07-14 and re-confirmed 2026-07-16/17 on Docker Desktop 4.77.0.
Two honest boundaries: (1) I did not disassemble /initd, so I can't say why it re-steps every 30 s rather than on demand — though the joined trace confirms each call writes a fresh backward ~1 ms correction and succeeds — and the fix direction (slew or magnitude-gate) holds regardless. (2) This trace explains the cache-flush loop and the log spam specifically; whether flushing alone accounts for every network symptom reported upstream is for the thread to judge.
Cross-references: microsoft/WSL#13777 (same symptom, correctly correlated with Docker Desktop by its reporters), systemd/systemd#43028 (the resolved-side half, closed with "report to the stepper").