Clock faults
Software reads two kinds of time. Elapsed time, CLOCK_MONOTONIC and the TSC,
is the machine’s own, and Machine time
controls it. The date, CLOCK_REALTIME, is what date, time() and
gettimeofday return, and on a real fleet it jumps, drifts and disagrees
between hosts. machine clock changes the date
the machine reads, for every process in it or for one container, and leaves
elapsed time alone.
| Command | What the date does |
|---|---|
jump +5s |
steps forward or back, as an NTP step or date -s does |
set 2027-03-28T00:59:50Z |
goes to that date |
drift +200ppm --container db |
gains 200 parts per million of machine time, 0.72 seconds an hour |
jump +4s --slew 30s --container db |
moves 4 seconds over 30 seconds of machine time, with no step |
jitter -200ms:200ms --every 10m |
is set to a drawn offset every 10 minutes of machine time |
leap insert |
repeats a second, 23:59:60, at the next UTC midnight |
reset |
returns to machine time, for the whole machine and every container |
The machine’s kernel makes each change, so a change takes effect when the run next executes. The run records every change: a replay makes it at the same instruction, a checkpoint keeps the date, and a branch starts with its parent’s date.
The machine’s date
jump, set and reset change the date every process in the machine reads,
in every container. The step is a real step of the kernel’s clock: a
timer armed for an absolute date sees it, and a timerfd with
TFD_TIMER_CANCEL_ON_SET is woken, which is how systemd and cron notice a
step.
1 | machine clock app jump +59m50s |
The answer shows the date as it stands and the change waiting for the run:
1 | date: 2026-03-01T00:01:29.614903749Z |
Steps add up: jump +5s and then jump -2s leave the date 3 seconds ahead.
set puts the date at a value, whatever steps came before it. Machine refuses
a date before 1970, or one on or after 2232-04-18T23:47:16Z, because the
kernel cannot set either.
A container’s date
With --container, a change moves one container’s date alone, as an offset
from the machine’s date. Every process of the container reads it, including
those docker exec and machine exec --container start. The other
containers keep the machine’s date.
1 | machine clock app jump -6m --container client |
The client now reads a date 6 minutes behind the server, so a certificate the server issued a minute ago is not valid yet for the client.
The offset reaches every way a program reads the date. clock_gettime stays
as fast as it is outside the machine, because the container’s processes still
read the date in the vDSO, without a system call. System calls, POSIX timers,
timerfd and clock_nanosleep agree with the container’s date, and so do the
futex waits behind pthread_cond_timedwait and sem_timedwait and message
queue timeouts. A restarted container keeps its offset, while a container
created again starts on the machine’s date.
--container takes a container’s id, its name or its Compose service. Machine
finds the container without running the machine, so a clock change made at a
breakpoint leaves the run at that breakpoint. Prefer the id: Machine knows it
as soon as Docker creates the container, and learns the name shortly after the
container starts. machine containers app lists both.
A stopped container that has an offset keeps it, and takes it again when it
starts. machine clock app reset --container db returns it to the machine’s
date, stopped or running. A container Docker removes, with docker rm or a
--fresh restart, loses its offset, and the container that replaces it starts
on the machine’s date. At most 8 containers have dates of their own at once;
the next is refused until one is reset or removed.
Drift and slew
A clock that runs fast or slow is a fault a jump cannot reproduce: the nodes’
dates move apart gradually rather than in one step, until an assumption about
skew breaks. drift makes one
container’s date gain or lose time at a rate of machine time:
1 | machine clock app drift +5000ppm --container node2 # 0.5% fast: 3s in 10 minutes |
No read sees a jump, and a timer armed in the container agrees with its drifting date: it fires when the container’s own date reaches the deadline, never before. At +100000ppm, a timerfd armed for 2 seconds ahead by the container’s date fired after 1.821 seconds of machine time, which is 2 seconds of a clock running 10% fast.
--slew moves a container’s date to a new value over a time instead of in one
step, as NTP slews a small correction:
1 | machine clock app jump +4s --for 2m --container db # off and back, two steps |
A slew runs until the date reaches its new value. A later change to the same
container, a drift included, stops the slew at the offset it has reached, so
set a drift before you start a slew. A slew moves the date at most half a second for each second of machine
time, so jump +4s --slew 8s is the fastest slew of 4 seconds. Machine
refuses a shorter one:
1 | ✗ A slew of +4s takes 8s at the least. |
drift applies to a container alone, never to the machine’s date. To make
all of the machine’s time run fast or slow, use the clock rate.
Jitter
An NTP-disciplined fleet is never exactly in sync: each host’s offset varies
within a bound. jitter sets the date to a value drawn around it each period:
1 | machine clock app jitter -200ms:200ms --every 10m --container api |
Every 10 minutes of machine time, api’s offset is set to a value from -200ms
to 200ms around the date without the jitter. The first step is taken when the
run next executes. A weight in brackets draws a choice more often:
-1s[1],0[8],1s[1] is in sync most of the time and a second off now and then.
A jitter takes 4 choices at most, each a whole number of microseconds.
The draws come from --seed, or from a seed drawn at random and shown. Give
that seed with --seed to step the date the same way again. A replay steps by
the same amounts at the same points, and a branch draws on from where its
parent was. A jump or a set moves the date under the jitter, which goes on
around the new date. machine clock app jitter off stops the jitter and
returns the date to where it would be without it.
Leap seconds
In 2012 a leap second livelocked Linux futexes, and services across the
industry went down with it. leap insert makes the kernel repeat a
second, 23:59:60, at the next UTC midnight of the machine’s date, and
leap delete makes it skip 23:59:59:
1 | machine clock app set 2026-12-31T23:59:50Z |
After the 20 seconds the date is a second behind where it would have been
without the leap. With leap delete it is a second ahead. A leap second moves the machine’s date and every container
with it, so leap takes no --container. leap off cancels a leap still
pending, and so does reset.
Undoing a change after a time
--for 2m takes a change back after 2 minutes of machine time, at the same
instruction in every replay. jump +4s --for 2m is a step forward and, 2
minutes later, a step back: the NTP correction that follows a host running
with a bad clock. jump, set, drift and jitter take --for.
The undo takes back the command’s own change. What else moved the date meanwhile stays: a drift’s accrual, a leap second, or another program’s step. A later change cancels an undo still pending.
Reading the date
machine clock app reads the date without running the machine. It shows the
machine’s date and its offset from machine time, then each container whose
date differs from it, with its offset, drift, slew and jitter. To see the date a
program reads, ask from inside its container, which runs the machine:
1 | machine exec app run --container db -- date -u |
The reading looks like this:
1 | date: 2026-12-31T23:59:54.977514123Z |
--container db shows one container, and machine -o json clock app gives
every field.
A change is taken when the run next executes, so the command that asks for it cannot say whether the machine’s kernel accepts it. Read the clock after the run that takes it. The reading names each change of the last batch the kernel refused, as you typed it, and why:
1 | machine clock app set 1970-01-01T00:00:01Z |
1 | date: 2026-03-01T00:00:40.556767815Z |
The jitter applied and the set did not. A refused change changes nothing.
Clock fault use cases
Each block below is a question a clock fault answers, and the commands that
ask it. Run the machine afterwards, with machine run app --within 2m or with
an --until the program prints, and read what it did.
1 | # Does the program refresh a token before it expires? |
How much skew the system tolerates
Fork one branch for each skew at the same checkpoint, and run each branch to the same point. Every branch starts from the identical machine, so the skew is the only difference:
1 | machine checkpoint app steady |
A jump inside one request
Most time bugs are check-then-use: the process checks a token’s expiry, the clock steps, and it uses what it checked. Stop the run where the check is done, jump, and go on:
1 | machine containers app # auth is 3f2a91c0d4e7 |
The jump finds the container by its id without running the machine, so the
run is still stopped at check_expiry when it takes the jump.
A step back reorders events
A database that stamps rows with the time they were written sorts them by that stamp. Step its container’s date back between two writes, and the second row sorts before the first:
1 | machine exec app run --container db -- psql -U postgres -tAc "create table ev(id serial, at timestamptz default clock_timestamp())" |
1 | 2|2026-03-01 00:50:42.230825+00 |
Any code that takes the newest stamp as the latest event, such as
last-write-wins or a cursor over at, now picks row 1.
Because every clock change is part of the run’s recording, a failure found
under skew comes back when you replay the recording; there is no timing to
reconstruct. Investigate it as any other failure, with
rewind, diff and the debugger.
What a clock change misses
- File timestamps. The kernel stamps files with its own clock, so
makein a container whose date is behind the machine’s reports clock skew. - Socket timestamps.
SO_TIMESTAMPandSIOCGSTAMPcarry the machine’s date, sopingin a skewed container reports the offset as round trip time. - Timers already armed. A container’s change does not move a deadline
armed before it; a timerfd with
TFD_TIMER_CANCEL_ON_SETis woken so the program can re-arm. - A container that sets the date. A container given
CAP_SYS_TIMEthat callssettimeofdaysets the machine’s date, as it would set a host’s; its own offset stays.