Repository navigation
fix(agent): region-vacated check never delays Terminate (#1456) - #1460
Merged
Merged
Conversation
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 #1456
Problem
terminaterancheckRegionVacatedafter the pre-stop hook, cleanup and the 5 s warning, and when no otherspawn:managedinstance was running or pending in the region it blocked 60 s (regionVacatedSettle) beforeprovider.Terminate, even with no notifier configured. The last spawn instance in a region was billed an extra idle minute on every TTL, cost-limit, idle and on-complete termination.Change (
pkg/agent/region_vacated.go,terminate,checkCompletion)a.notifier == nil, i.e.spawn:notify-urlunset; spored has no per-event subscription, the bot filters, so a notifier is the only signal): the check does not run. NoDescribeInstances, no wait.checkCompletionbeforeannounceCompletion(so before--completion-delay) for on-complete terminate, at the top ofterminatefor TTL, cost limit and idle terminate. It takes the first count in a goroutine.terminatecuts the settle at its user warning, so the re-count runs during the existing 5 s warning sleep. After the sleep it cancels the probe and reads the verdict. A count still in flight returns as unknown and is treated as "not vacated", so a slow EC2 API never holdsTerminate.region_vacatedis still sent beforeTerminate, from the same literalNotifycall thatTestSporedNotifyEventsHandledBySporeBotdiscovers.region_vacatedmessage (notify-only) where it did not before. The trade is deliberate: cost control over a chat message.regionVacatedSettleis removed; the probe has no timer.Latency, completion file to
Terminatecall (defaults, no pre-stop)TTL, cost-limit and idle terminate: the 60 s comes off the same way (tick phase + pre-stop + cleanup + 5 s). Stop/hibernate never ran the check. A Spot interruption is terminated by EC2, not spored.
Gates (
pkg/agent/region_vacated_test.go), counted through the stub provider, the recording notifier and thegraceSleepseam, never timed; each runs over all four paths (TTL, cost limit, idle terminate, on-complete terminate)TestRegionVacatedCheckCostsNothingWithoutNotifier: no notifier, empty region → terminated, 0 counts.TestRegionVacatedNotificationWithNotifier: vacated → exactly oneregion_vacated, already sent whenTerminateis called; relaunch during the settle ({0, 1}) → none; others remain → none (1 count); unknown → none.TestRegionVacatedSettleOverlapsCompletionDelay: the probe is running during the--completion-delaywait.TestRegionVacatedCheckNeverHoldsTerminate: count 1 or count 2 blocks until its context is cancelled →Terminateis still called, and noregion_vacatedis sent.Compiling reverts, each watched failing:
a.notifier == nilguard → CostsNothing fails on all 4 paths ("2 region counts with no notifier configured, want 0");n := 0→relaunch during settlefails on all 4 paths;checkCompletion→ Overlaps fails ("not running during the --completion-delay wait");p.cancel()invacated()→ NeverHolds hangs in(*regionVacatedProbe).vacated(panic: test timed outat-timeout 30s);agent.goto origin/main, withregion_vacated.goand the Overlaps test removed so it compiles: CostsNothing/ttl FAILS after 60.00 s (the billed minute, 2 counts);relaunch during settlepasses (the protection is preserved); NeverHolds hangs in the old synchronous count.Also
spawn upgrade-spored <instance>. Nothing else is needed./var/log/spored.log, not the journal.Checks:
make check(from /private/tmp) OK,make lint0 issues,semgrep scan --config=auto --error .clean,go test -race -count=3on the agent lifecycle tests OK. No help text, exported API or user-data changes.