Repository navigation
Conversation
This was referenced Oct 15, 2026
A replacement EC2 launches from a leaked persistent Spot request boots the original's user data. The bootstrap started --command in the background before spored, so the replacement re-ran the workload from the start, side effects included, while spored was deciding to retire it. New `spored is-spot-replacement` runs spotrequest.DetectReplacement and exits 0 (replacement), 1 (not) or 2 (unknown). It retries an inconclusive read every 5s for up to --timeout (60s), and not at all on an IAM refusal. The Linux bootstrap calls it twice through spawn_is_spot_replacement: inside the backgrounded --command subshell, ahead of the command, so it never delays spored's start; and right after spored starts, where a replacement exits the script. So storage, plugins, the container, custom user data and the MPI, batch-queue and pool-worker scripts appended later don't run either. Definite answers are cached in /run/spawn. Only exit 0 skips. Unknown, a missing spored, an older spored without the subcommand (cobra exits 1) and a timeout all run the workload, as before. Holding would strand originals whenever EC2/IMDS is slow or a custom role can't read tags; a replacement that gets past it is still retired by spored and alarmed by the reaper. The Windows bootstrap starts no workload (it runs no --command or user data), so it has nothing to gate; a comment says what to do if it gains one. Also adds TestRunDaemonStartsTheReplacementCheck, which fails if runDaemon stops starting the #995 check (the gap #1008 noted), and a Detection.Err field so the subcommand can tell an IAM refusal from a transient failure. The bootstrap tests run the generated --command block and the post-spored tail under bash with stubbed spored and su; each new test was watched failing against a compiling revert. (#1007)
…1007) spored reads /etc/spawn/plugins.json once, at startup, and the bootstrap writes it just after `systemctl start spored`. Putting the stop's EC2 round trip between the two would have made spored miss the declarations on every original instance. The stop now follows the plugins block; a gate keeps it there. The existing race is filed as #1023. (#1007)
The notification comes from the replacement, whose instance id nobody registered with spore-bot, so the bot's registration gate dropped every DM and SMS for it. spored now also sends original_instance_id (via Notifier.WithOriginalInstance), which spore-bot uses for this event alone. Older bots ignore the unknown field. (#1007)
…1023's plugin order (#1007) The sandboxed bootstrap tests execute the Linux user data under bash with stubbed spored and su, which the Windows CI job (#973) cannot reproduce, so they skip there as the other Linux-bootstrap execution tests do (#1002). Rebased onto #1023/#1045, plugins.json is written before spored starts, so the post-spored stop sits straight after the bootstrap body; the changelog and the ordering test's comment now say so. (#1007)
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 #1007
Stacked on #1008. Review and merge #1008 first; this PR's base is
fix/995.What
spored is-spot-replacement: runsspotrequest.DetectReplacementand exits 0 for a replacement, 1 for not a replacement, 2 for unknown. It retries an inconclusive read every 5s for up to--timeout(default 60s). An IAM refusal (UnauthorizedOperation/AccessDenied*) is not retried. It reads IMDS and EC2 directly rather than throughprovider.NewEC2Provider, so an IMDS failure reports unknown instead of falling back to the local provider.pkg/launcher/bootstrap.go): aspawn_is_spot_replacementshell function, called in two places:--commandsubshell, before the gates and the command. Inside the subshell, a slow check can't delay spored's start (spored#65). A skipped command writes noSPAWN_COMPLETE.systemctl start sporedand the plugin declarations. On a replacement the script exits there, so storage, the container, custom user data and the MPI, batch-queue and pool-worker scripts appended after the bootstrap don't run either. The stop comes afterplugins.jsonbecause spored reads that file only at startup: the check's EC2 round trip, placed ahead of the declarations, would make every original miss its plugins.TestSpotReplacementStopComesAfterPluginDeclarationsgates the order, and the underlying race is filed as Linux bootstrap writes /etc/spawn/plugins.json after starting spored, which reads it only at startup #1023.Definite answers (0 or 1) are cached in
/run/spawn, which is tmpfs.buildWindowsUserDataruns no--commandand no custom user data. A comment says to gate any future workload start the same way.Detection.Err, so the subcommand can tell an IAM refusal apart from a transient failure.Unknown: run the workload, with a bounded retry
Only exit 0 skips the workload. Unknown runs it, and so does a missing spored, an older spored without the subcommand (cobra exits 1; checked) and a
timeout 120hit. Holding instead would strand a real original whenever EC2 or IMDS is slow, or a custom--iam-rolecan't callDescribeInstances. Originals vastly outnumber replacements. A replacement that slips through is still retired by spored's own check (#1008) and reported by the reaper's alarm (#984). An original normally answers on the firstDescribeInstances, because it is taggedspawn:managed=true. So the retry budget is only spent on a launch that is already degraded.Cost: one IMDS read and one or two EC2 calls before the post-spored steps of every launch.
Tests
pkg/launcher/bootstrap_spot_replacement_test.goruns the real generated--commandblock and the post-spored tail under bash. spored and su are stubbed, and absolute paths are rewritten into a temp dir. Cases cover spored exiting 0, 1, 2, 3 and 124, and spored being missing. They also check that the guard sits inside the subshell ahead ofsu, that only definite answers are cached, and that the script passesbash -n.cmd/spored/is_spot_replacement_test.go: the exit-code contract, the retry bound (fake clock), and no retry on an IAM refusal. AlsoTestRunDaemonStartsTheReplacementCheck(the gap Have spored retire a Spot replacement it finds itself running on (#995) #1008 noted): it readsrunDaemon's AST and requiresgo replacementCheck{...}.run(...)withshutdown: powerOffandr/notify/sleepset, started beforeagent.NewAgent.go vetclean). Reverts tried: the command guard changed toif false; the stop script replaced with_ =; unknown failing closed;runDaemon'sgostatement replaced with_ = replacementCheck{}; the exit mapping swapped; the cache disabled.make check: the only failure is the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nestedpasses; golangci-lint reports 0 issues on the touched packages.Filed
--commandand--user-data.plugins.jsonis written after spored starts, and spored reads it only at startup.Not verified
Nothing here has been run against a real Spot replacement. As with #995, it assumes cloud-init runs user data on the replacement.