Repository navigation
fix: keep VM clocks on the Mac's time after sleep - #26
Merged
Merged
Conversation
A VM is frozen while the Mac sleeps and nothing in the guest set its clock again: the kernel reads the virtual RTC once at boot and ntpd was not enabled. Clocks were seen hours to days behind (4 d, ~2 d, 11 h), breaking database now(), logs and signed requests until a restart. - GuestClockSync: pushes the Mac's epoch over the vsock shell and steps the guest clock when it is more than 2 s off; also enables and starts busybox ntpd (images built before this pick it up). - GuestClockSyncScheduler: syncs the Docker VM and running Alpine machines when the engine comes up, on wake (with retries), on clock and time-zone changes, and every minute; corrections go to host.log. - "Follow this Mac" time zone now follows a zone change right away. - New images enable ntpd (provision script and Dockerfile). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Deploying dockz with
|
| Latest commit: |
6ef0ce4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://665c6cb0.dockz.pages.dev |
| Branch Preview URL: | https://fix-guest-clock-sync.dockz.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The Docker VM's clock fell behind after the Mac slept — seen 4 days, ~2 days and 11 hours behind — so Postgres
now(), logs and signed requests (S3, TLS, JWT) were wrong until DockZ restarted. A VM is frozen while the Mac sleeps (measured: 108 h of wall time, 45.5 h of guest uptime), and nothing in the guest set its clock again: the kernel reads the virtual RTC once at boot, and busyboxntpdshipped but was not enabled.Two layers:
GuestClockSync+GuestClockSyncScheduler): the Mac's epoch goes over the vsock shell and the guest clock is stepped when more than 2 s off. Runs for the Docker VM and running Alpine machines when the engine comes up, on wake (with retries), on clock and time-zone changes, and every minute. Corrections are written tohost.log. Works offline and acts immediately.ntpd(provision script and Dockerfile); the sync script enables and starts it on older images.Also: with the time zone on "follow this Mac", a Mac time-zone change reaches the VM right away instead of at the next restart.
Cloud-image machines (Debian/Ubuntu) have no vsock agent and run their own
systemd-timesyncd; they are left alone.Checklist
swift run -c release DockzApp testpasses locally (457 checks)test-runner-*.swiftfile[Unreleased]inCHANGELOG.mdHow I verified it
On a throwaway data folder (
-dockz.storageRoot /tmp/dzs), with a disk image built by this branch:ntpdenabled and running, guest clock matches the Mac.ntpd(as on an older image), set the guest clock 2 days back: the periodic sync set it right within ~40 s, loggedclock: Docker VM was 2 d 0 h behind — set to the Mac's time (periodic check), and re-enabledntpd.ntpddaemon had not corrected it yet. It works (a one-shotntpd -qstepped a 1 h offset immediately), but its poll interval grows to tens of minutes once settled. So it is a slow backstop for the rare "DockZ hung while the VM runs" case; wake and the 1-minute check are the main path./bin/shwithdatefaked.Not tested: a real Mac sleep/wake cycle (it can't be triggered from a script); that path is the same sync, triggered by
NSWorkspace.didWakeNotification.🤖 Generated with Claude Code