Repository navigation
Merged
Conversation
This was referenced Oct 15, 2026
scttfrdmn
force-pushed
the
fix/945
branch
2 times, most recently
from
October 17, 2026 01:53
1d585d7 to
f981b02
Compare
scttfrdmn
added a commit
that referenced
this pull request
Oct 17, 2026
…ion (#987) A hibernated instance resumes the same spored process, which carried its pre-hibernate state into the new run. The pre-stop hook and task record were spent, so the next stop or TTL terminate skipped them. The DNS name Cleanup deleted came back only at the hourly renewal, with the IP from the first boot. lastActivityTime was hours old, so the first idle tick hibernated again within a minute. The plugins Cleanup stopped stayed stopped. Detection runs on each monitor tick (checkResume) and needs no sleep hook: - The primary signal is CLOCK_BOOTTIME - CLOCK_MONOTONIC (the idea from #965) growing by 1s or more. Only a suspend moves it. sysSuspendedTime lives in suspend_linux.go / suspend_other.go, so it does not collide with #965's kernelclock.go. - The backup signal is the wall clock running at least 5 minutes ahead of Go's monotonic clock between ticks. - resumedBetween is pure and table-tested. onResume re-arms preStopDone and taskFlushDone, restarts the idle timer and warning, clears the stop backoff, resets the CPU, network and disk baselines, and marks a completion file already acted on as spent. checkCompletion ignores it until its mtime changes. onResume then re-reads the public IP from IMDS and calls restoreAfterCleanup (renamed from restoreAfterFailedStop), which re-registers DNS, the registry entry and the plugins. The new IP is held in a guarded currentIP field behind publicIP(). identity is shared unguarded with the provider, the plugin runtime and off-loop goroutines, so it is not mutated. The DNS register and delete calls and the ready-url hosts read publicIP(). (#987)
scttfrdmn
added a commit
that referenced
this pull request
Oct 17, 2026
…ion (#987) A hibernated instance resumes the same spored process, which carried its pre-hibernate state into the new run. The pre-stop hook and task record were spent, so the next stop or TTL terminate skipped them. The DNS name Cleanup deleted came back only at the hourly renewal, with the IP from the first boot. lastActivityTime was hours old, so the first idle tick hibernated again within a minute. The plugins Cleanup stopped stayed stopped. Detection runs on each monitor tick (checkResume) and needs no sleep hook: - The primary signal is CLOCK_BOOTTIME - CLOCK_MONOTONIC (the idea from #965) growing by 1s or more. Only a suspend moves it. sysSuspendedTime lives in suspend_linux.go / suspend_other.go, so it does not collide with #965's kernelclock.go. - The backup signal is the wall clock running at least 5 minutes ahead of Go's monotonic clock between ticks. - resumedBetween is pure and table-tested. onResume re-arms preStopDone and taskFlushDone, restarts the idle timer and warning, clears the stop backoff, resets the CPU, network and disk baselines, and marks a completion file already acted on as spent. checkCompletion ignores it until its mtime changes. onResume then re-reads the public IP from IMDS and calls restoreAfterCleanup (renamed from restoreAfterFailedStop), which re-registers DNS, the registry entry and the plugins. The new IP is held in a guarded currentIP field behind publicIP(). identity is shared unguarded with the provider, the plugin runtime and off-loop goroutines, so it is not mutated. The DNS register and delete calls and the ready-url hosts read publicIP(). (#987)
scttfrdmn
added a commit
that referenced
this pull request
Oct 17, 2026
…ion (#987) A hibernated instance resumes the same spored process, which carried its pre-hibernate state into the new run. The pre-stop hook and task record were spent, so the next stop or TTL terminate skipped them. The DNS name Cleanup deleted came back only at the hourly renewal, with the IP from the first boot. lastActivityTime was hours old, so the first idle tick hibernated again within a minute. The plugins Cleanup stopped stayed stopped. Detection runs on each monitor tick (checkResume) and needs no sleep hook: - The primary signal is CLOCK_BOOTTIME - CLOCK_MONOTONIC (the idea from #965) growing by 1s or more. Only a suspend moves it. sysSuspendedTime lives in suspend_linux.go / suspend_other.go, so it does not collide with #965's kernelclock.go. - The backup signal is the wall clock running at least 5 minutes ahead of Go's monotonic clock between ticks. - resumedBetween is pure and table-tested. onResume re-arms preStopDone and taskFlushDone, restarts the idle timer and warning, clears the stop backoff, resets the CPU, network and disk baselines, and marks a completion file already acted on as spent. checkCompletion ignores it until its mtime changes. onResume then re-reads the public IP from IMDS and calls restoreAfterCleanup (renamed from restoreAfterFailedStop), which re-registers DNS, the registry entry and the plugins. The new IP is held in a guarded currentIP field behind publicIP(). identity is shared unguarded with the provider, the plugin runtime and off-loop goroutines, so it is not mutated. The DNS register and delete calls and the ready-url hosts read publicIP(). (#987)
scttfrdmn
added a commit
that referenced
this pull request
Oct 17, 2026
…ion (#987) (#1020) * Reset spored's per-boot state when the instance resumes from hibernation (#987) A hibernated instance resumes the same spored process, which carried its pre-hibernate state into the new run. The pre-stop hook and task record were spent, so the next stop or TTL terminate skipped them. The DNS name Cleanup deleted came back only at the hourly renewal, with the IP from the first boot. lastActivityTime was hours old, so the first idle tick hibernated again within a minute. The plugins Cleanup stopped stayed stopped. Detection runs on each monitor tick (checkResume) and needs no sleep hook: - The primary signal is CLOCK_BOOTTIME - CLOCK_MONOTONIC (the idea from #965) growing by 1s or more. Only a suspend moves it. sysSuspendedTime lives in suspend_linux.go / suspend_other.go, so it does not collide with #965's kernelclock.go. - The backup signal is the wall clock running at least 5 minutes ahead of Go's monotonic clock between ticks. - resumedBetween is pure and table-tested. onResume re-arms preStopDone and taskFlushDone, restarts the idle timer and warning, clears the stop backoff, resets the CPU, network and disk baselines, and marks a completion file already acted on as spent. checkCompletion ignores it until its mtime changes. onResume then re-reads the public IP from IMDS and calls restoreAfterCleanup (renamed from restoreAfterFailedStop), which re-registers DNS, the registry entry and the plugins. The new IP is held in a guarded currentIP field behind publicIP(). identity is shared unguarded with the provider, the plugin runtime and off-loop goroutines, so it is not mutated. The DNS register and delete calls and the ready-url hosts read publicIP(). (#987) * Read the pre-stop hook's log in either encoding, for the Windows runner (#987) * Resume tests: a quiet machine has no active sessions on Windows either (#987)
…tonic clock (#945) Resume detection (#987) now reads its suspended time through the same kernel-clock reader (readKernelClocks) instead of a second CLOCK_BOOTTIME/CLOCK_MONOTONIC reader, so the compute clock and the per-boot reset cannot disagree about a hibernation. suspend_linux.go and suspend_other.go are folded into kernelclock.go / sys_*.go.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Fixes #945
Stacked on #947, which is stacked on #916. Merge those first; this PR's base is
fix/928.The bug
A hibernate-and-resume keeps the same boot. The boot_id,
/run/spored/compute-clock.jsonand the same-boot checkpoint all survive it.spored status, and a spored restarted after the resume, measured running time as wall-now minus a wall timestamp written before the hibernation, so the whole hibernation counted as compute. That also fed--cost-limit.A third case beyond the issue: the daemon's "count from the kernel's boot" origin came from
/proc/uptime, which is CLOCK_BOOTTIME and includes suspend. A spored that started after a hibernation earlier in the boot counted that hibernation too.Approach: kernel clocks rather than catching the event
I chose CLOCK_MONOTONIC and CLOCK_BOOTTIME over a systemd sleep hook or EC2 state-transition times:
How it works:
{0,0}when counting from kernel boot. It writes them into the published compute clock (with itsboot_id, because the readings only mean something within one boot) and into the durable checkpoint.TotalComputeSecondsthen counts on CLOCK_MONOTONIC from that origin.TotalSecondsand counts on from spored's start. That loses the seconds since its last write (Cleanup writes it on SIGTERM) instead of risking counting a hibernation.Status
spored statusaddshibernated_secondsand shows it in the elapsed breakdown, e.g.8h 1m (1m 0s compute · 10s boot · 8h 0m hibernated). Hibernated time is subtracted before the stopped residue is computed, so it is not counted twice. It is included in the storage cost, because EBS bills while hibernated and compute does not. The EC2-side view of a stopped instance already shows EC2's StateReason (Client.UserInitiatedHibernate), so that view is unchanged.Windows (filed #962)
Windows has no published clock and no checkpoint, so the cross-process cases do not arise there. But Go's Windows monotonic clock is
KUSER_SHARED_DATA.InterruptTime, which keeps counting through sleep and hibernation. So the daemon's own in-process count on Windows does include the hibernation.sysKernelClocksis a documented stub there for now. #962 describes the QueryUnbiasedInterruptTime fix, which needs a Windows instance to verify.Tests
New gates:
pkg/agent/hibernation_test.go:cmd/spored/status_cost_test.go:TestStatusReport_HibernatedTimeIsNotComputepkg/agent/sys_linux_kernelclock_test.go: the real-kernel read, Linux onlyEach gate was watched failing against a revert that compiles (
go vetclean):thisBootRunning(4 fail)OriginKnown=falsevalidOrigin→trueHibernatedTime()*0Existing
resolveComputeStarttests go through aresolveWallhelper, because the function now returns a struct. Their wall-clock expectations are unchanged.make check: everything passes except the knownTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker(no Docker daemon).make check-nested: all 9 modules clean. Cross-compiled for Linux and Windows, including the test binaries.Caveats
stoppingphase while RAM is saved, and the restore boot. CLOCK_MONOTONIC counts neither, because the snapshot is taken before the image write. So compute undercounts by roughly that minute or two around each hibernation, and status shows it as hibernated. That errs in the direction the existing rules prefer.TestSysKernelClocks_ReadsBothClocksruns only on Linux, so in CI. It was not run locally (macOS).